Changes in src/libcfa/concurrency/invoke.h [78b3f52:5c81105]
- File:
-
- 1 edited
-
src/libcfa/concurrency/invoke.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/invoke.h
r78b3f52 r5c81105 1 #include <stdbool.h> 2 #include <stdint.h> 1 3 4 #ifdef __CFORALL__ 5 extern "C" { 6 #endif 7 8 #if ! defined(__CFA_INVOKE_PRIVATE__) 2 9 #ifndef _INVOKE_H_ 3 10 #define _INVOKE_H_ 4 11 5 struct coVtable { 6 void (*main)(void*); 7 struct coroutine* (*this_coroutine)(void*); 8 }; 12 #define OFFSET_OF(type, field) ((intptr_t)( &((type*)0)->field)) 13 #define VPTR_OFFSET(type, vptr, field) (OFFSET_OF(type, field) - OFFSET_OF(type, vptr)) 9 14 10 struct coStack_t { 11 unsigned int size; // size of stack 12 void *storage; // pointer to stack 13 void *limit; // stack grows towards stack limit 14 void *base; // base of stack 15 void *context; // address of cfa_context_t 16 void *top; // address of top of storage 17 bool userStack; 18 }; 15 struct coVtable_t { 16 void (*main)(void*); 17 intptr_t offset_coroutine; 18 intptr_t offset_object; 19 }; 19 20 21 typedef struct coVtable_t* covptr_t; 20 22 21 enum coroutine_state { Start, Inactive, Active, Halt }; 23 static inline struct coroutine* get_coroutine(covptr_t* vthis) { 24 return (struct coroutine*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_coroutine) ); 25 } 22 26 23 struct coroutine { 24 struct coStack_t stack; 25 const char *name; // textual name for coroutine/task, initialized by uC++ generated code 26 int errno_; // copy of global UNIX variable errno 27 enum coroutine_state state; // current execution status for coroutine 28 bool notHalted; // indicate if execuation state is not halted 27 static inline void* get_object(covptr_t* vthis) { 28 return (void*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_object) ); 29 } 29 30 30 struct coroutine *starter; // first coroutine to resume this one 31 struct coroutine *last; // last coroutine to resume this one 32 }; 31 struct coStack_t { 32 unsigned int size; // size of stack 33 void *storage; // pointer to stack 34 void *limit; // stack grows towards stack limit 35 void *base; // base of stack 36 void *context; // address of cfa_context_t 37 void *top; // address of top of storage 38 bool userStack; 39 }; 33 40 41 enum coroutine_state { Start, Inactive, Active, Halt }; 42 43 struct coroutine { 44 struct coStack_t stack; 45 const char *name; // textual name for coroutine/task, initialized by uC++ generated code 46 int errno_; // copy of global UNIX variable errno 47 enum coroutine_state state; // current execution status for coroutine 48 bool notHalted; // indicate if execuation state is not halted 49 50 struct coroutine *starter; // first coroutine to resume this one 51 struct coroutine *last; // last coroutine to resume this one 52 }; 53 54 void invokeCoroutine(covptr_t* this); 55 void startCoroutine(covptr_t* this, void (*invoke)(covptr_t*)); 34 56 #endif //_INVOKE_H_ 57 #else //! defined(__CFA_INVOKE_PRIVATE__) 58 #ifndef _INVOKE_PRIVATE_H_ 59 #define _INVOKE_PRIVATE_H_ 60 61 struct machine_context_t { 62 void *SP; 63 void *FP; 64 void *PC; 65 }; 66 67 // assembler routines that performs the context switch 68 extern void coInvokeStub( void ); 69 void CtxSwitch( void *from, void *to ) asm ("CtxSwitch"); 70 71 #endif //_INVOKE_PRIVATE_H_ 72 #endif //! defined(__CFA_INVOKE_PRIVATE__) 73 #ifdef __CFORALL__ 74 } 75 #endif
Note:
See TracChangeset
for help on using the changeset viewer.