ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since 17e5e2b was             596f987b, checked in by Thierry Delisle <tdelisle@…>, 9 years ago | 
        
          | 
Some optimization and clean-up of coroutines
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.7 KB | 
      
      
| Line |  | 
|---|
| 1 | #include <stdbool.h> | 
|---|
| 2 | #include <stdint.h> | 
|---|
| 3 |  | 
|---|
| 4 | #ifdef __CFORALL__ | 
|---|
| 5 | extern "C" { | 
|---|
| 6 | #endif | 
|---|
| 7 |  | 
|---|
| 8 | #if ! defined(__CFA_INVOKE_PRIVATE__) | 
|---|
| 9 | #ifndef _INVOKE_H_ | 
|---|
| 10 | #define _INVOKE_H_ | 
|---|
| 11 |  | 
|---|
| 12 | #define unlikely(x)    __builtin_expect(!!(x), 0) | 
|---|
| 13 |  | 
|---|
| 14 | struct coStack_t { | 
|---|
| 15 | unsigned int size;          // size of stack | 
|---|
| 16 | void *storage;                      // pointer to stack | 
|---|
| 17 | void *limit;                        // stack grows towards stack limit | 
|---|
| 18 | void *base;                         // base of stack | 
|---|
| 19 | void *context;                      // address of cfa_context_t | 
|---|
| 20 | void *top;                          // address of top of storage | 
|---|
| 21 | bool userStack; | 
|---|
| 22 | }; | 
|---|
| 23 |  | 
|---|
| 24 | enum coroutine_state { Start, Inactive, Active, Halt, Primed }; | 
|---|
| 25 |  | 
|---|
| 26 | struct coroutine { | 
|---|
| 27 | struct coStack_t stack; | 
|---|
| 28 | const char *name;                   // textual name for coroutine/task, initialized by uC++ generated code | 
|---|
| 29 | int errno_;                         // copy of global UNIX variable errno | 
|---|
| 30 | enum coroutine_state state; // current execution status for coroutine | 
|---|
| 31 | bool notHalted;                     // indicate if execuation state is not halted | 
|---|
| 32 |  | 
|---|
| 33 | struct coroutine *starter;  // first coroutine to resume this one | 
|---|
| 34 | struct coroutine *last;             // last coroutine to resume this one | 
|---|
| 35 | }; | 
|---|
| 36 |  | 
|---|
| 37 | #endif //_INVOKE_H_ | 
|---|
| 38 | #else //! defined(__CFA_INVOKE_PRIVATE__) | 
|---|
| 39 | #ifndef _INVOKE_PRIVATE_H_ | 
|---|
| 40 | #define _INVOKE_PRIVATE_H_ | 
|---|
| 41 |  | 
|---|
| 42 | struct machine_context_t { | 
|---|
| 43 | void *SP; | 
|---|
| 44 | void *FP; | 
|---|
| 45 | void *PC; | 
|---|
| 46 | }; | 
|---|
| 47 |  | 
|---|
| 48 | // assembler routines that performs the context switch | 
|---|
| 49 | extern void CtxInvokeStub( void ); | 
|---|
| 50 | void CtxSwitch( void *from, void *to ) asm ("CtxSwitch"); | 
|---|
| 51 |  | 
|---|
| 52 | #endif //_INVOKE_PRIVATE_H_ | 
|---|
| 53 | #endif //! defined(__CFA_INVOKE_PRIVATE__) | 
|---|
| 54 | #ifdef __CFORALL__ | 
|---|
| 55 | } | 
|---|
| 56 | #endif | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.