Changeset e84ab3d for libcfa/src/concurrency/coroutine.hfa
- Timestamp:
- Jul 5, 2021, 4:44:20 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7f62b708
- Parents:
- ee23a8d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
ree23a8d re84ab3d 39 39 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) { 40 40 void main(T & this); 41 $coroutine* get_coroutine(T & this);41 coroutine$ * get_coroutine(T & this); 42 42 }; 43 43 44 #define DECL_COROUTINE(X) static inline $coroutine* get_coroutine(X& this) { return &this.__cor; } void main(X& this)44 #define DECL_COROUTINE(X) static inline coroutine$* get_coroutine(X& this) { return &this.__cor; } void main(X& this) 45 45 46 46 //----------------------------------------------------------------------------- … … 49 49 // void ^?{}( coStack_t & this ); 50 50 51 void ?{}( $coroutine& this, const char name[], void * storage, size_t storageSize );52 void ^?{}( $coroutine& this );53 54 static inline void ?{}( $coroutine& this) { this{ "Anonymous Coroutine", 0p, 0 }; }55 static inline void ?{}( $coroutine& this, size_t stackSize) { this{ "Anonymous Coroutine", 0p, stackSize }; }56 static inline void ?{}( $coroutine& this, void * storage, size_t storageSize ) { this{ "Anonymous Coroutine", storage, storageSize }; }57 static inline void ?{}( $coroutine& this, const char name[]) { this{ name, 0p, 0 }; }58 static inline void ?{}( $coroutine& this, const char name[], size_t stackSize ) { this{ name, 0p, stackSize }; }51 void ?{}( coroutine$ & this, const char name[], void * storage, size_t storageSize ); 52 void ^?{}( coroutine$ & this ); 53 54 static inline void ?{}( coroutine$ & this) { this{ "Anonymous Coroutine", 0p, 0 }; } 55 static inline void ?{}( coroutine$ & this, size_t stackSize) { this{ "Anonymous Coroutine", 0p, stackSize }; } 56 static inline void ?{}( coroutine$ & this, void * storage, size_t storageSize ) { this{ "Anonymous Coroutine", storage, storageSize }; } 57 static inline void ?{}( coroutine$ & this, const char name[]) { this{ name, 0p, 0 }; } 58 static inline void ?{}( coroutine$ & this, const char name[], size_t stackSize ) { this{ name, 0p, stackSize }; } 59 59 60 60 //----------------------------------------------------------------------------- … … 63 63 void prime(T & cor); 64 64 65 static inline struct $coroutine* active_coroutine() { return active_thread()->curr_cor; }65 static inline struct coroutine$ * active_coroutine() { return active_thread()->curr_cor; } 66 66 67 67 //----------------------------------------------------------------------------- … … 73 73 74 74 forall(T &) 75 void __cfactx_start(void (*main)(T &), struct $coroutine* cor, T & this, void (*invoke)(void (*main)(void *), void *));76 77 extern void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine*) __attribute__ ((__noreturn__));75 void __cfactx_start(void (*main)(T &), struct coroutine$ * cor, T & this, void (*invoke)(void (*main)(void *), void *)); 76 77 extern void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct coroutine$ *) __attribute__ ((__noreturn__)); 78 78 79 79 extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch"); … … 82 82 // Private wrappers for context switch and stack creation 83 83 // Wrapper for co 84 static inline void $ctx_switch( $coroutine * src, $coroutine* dst ) __attribute__((nonnull (1, 2))) {84 static inline void $ctx_switch( coroutine$ * src, coroutine$ * dst ) __attribute__((nonnull (1, 2))) { 85 85 // set state of current coroutine to inactive 86 86 src->state = src->state == Halted ? Halted : Blocked; 87 87 88 88 // get the active thread once 89 $thread* athrd = active_thread();89 thread$ * athrd = active_thread(); 90 90 91 91 // Mark the coroutine … … 124 124 // will also migrate which means this value will 125 125 // stay in syn with the TLS 126 $coroutine* src = active_coroutine();126 coroutine$ * src = active_coroutine(); 127 127 128 128 assertf( src->last != 0, … … 141 141 forall(T & | is_coroutine(T)) 142 142 void __cfaehm_cancelled_coroutine( 143 T & cor, $coroutine* desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) );143 T & cor, coroutine$ * desc, EHM_DEFAULT_VTABLE(CoroutineCancelled, (T)) ); 144 144 145 145 // Resume implementation inlined for performance … … 151 151 // will also migrate which means this value will 152 152 // stay in syn with the TLS 153 $coroutine* src = active_coroutine();154 $coroutine* dst = get_coroutine(cor);153 coroutine$ * src = active_coroutine(); 154 coroutine$ * dst = get_coroutine(cor); 155 155 156 156 if( unlikely(dst->context.SP == 0p) ) { … … 180 180 } 181 181 182 static inline void resume( $coroutine* dst ) __attribute__((nonnull (1))) {182 static inline void resume( coroutine$ * dst ) __attribute__((nonnull (1))) { 183 183 // optimization : read TLS once and reuse it 184 184 // Safety note: this is preemption safe since if … … 186 186 // will also migrate which means this value will 187 187 // stay in syn with the TLS 188 $coroutine* src = active_coroutine();188 coroutine$ * src = active_coroutine(); 189 189 190 190 // not resuming self ?
Note: See TracChangeset
for help on using the changeset viewer.