Changes in src/libcfa/concurrency/invoke.h [5c81105:78b3f52]
- File:
-
- 1 edited
-
src/libcfa/concurrency/invoke.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/invoke.h
r5c81105 r78b3f52 1 #include <stdbool.h>2 #include <stdint.h>3 1 4 #ifdef __CFORALL__5 extern "C" {6 #endif7 8 #if ! defined(__CFA_INVOKE_PRIVATE__)9 2 #ifndef _INVOKE_H_ 10 3 #define _INVOKE_H_ 11 4 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)) 5 struct coVtable { 6 void (*main)(void*); 7 struct coroutine* (*this_coroutine)(void*); 8 }; 14 9 15 struct coVtable_t { 16 void (*main)(void*); 17 intptr_t offset_coroutine; 18 intptr_t offset_object; 19 }; 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 }; 20 19 21 typedef struct coVtable_t* covptr_t;22 20 23 static inline struct coroutine* get_coroutine(covptr_t* vthis) { 24 return (struct coroutine*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_coroutine) ); 25 } 21 enum coroutine_state { Start, Inactive, Active, Halt }; 26 22 27 static inline void* get_object(covptr_t* vthis) { 28 return (void*) ( ((intptr_t)vthis) + ((intptr_t)(*vthis)->offset_object) ); 29 } 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 30 29 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 }; 30 struct coroutine *starter; // first coroutine to resume this one 31 struct coroutine *last; // last coroutine to resume this one 32 }; 40 33 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 code46 int errno_; // copy of global UNIX variable errno47 enum coroutine_state state; // current execution status for coroutine48 bool notHalted; // indicate if execuation state is not halted49 50 struct coroutine *starter; // first coroutine to resume this one51 struct coroutine *last; // last coroutine to resume this one52 };53 54 void invokeCoroutine(covptr_t* this);55 void startCoroutine(covptr_t* this, void (*invoke)(covptr_t*));56 34 #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 switch68 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.