Changeset ac2b598 for libcfa/src/concurrency/coroutine.hfa
- Timestamp:
- Feb 24, 2020, 2:21:03 PM (3 years ago)
- Branches:
- arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 959f6ad
- Parents:
- 0f2c555
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
r0f2c555 rac2b598 25 25 trait is_coroutine(dtype T) { 26 26 void main(T & this); 27 coroutine_desc* get_coroutine(T & this);27 $coroutine * get_coroutine(T & this); 28 28 }; 29 29 30 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this)30 #define DECL_COROUTINE(X) static inline $coroutine* get_coroutine(X& this) { return &this.__cor; } void main(X& this) 31 31 32 32 //----------------------------------------------------------------------------- … … 35 35 // void ^?{}( coStack_t & this ); 36 36 37 void ?{}( coroutine_desc& this, const char name[], void * storage, size_t storageSize );38 void ^?{}( coroutine_desc& this );37 void ?{}( $coroutine & this, const char name[], void * storage, size_t storageSize ); 38 void ^?{}( $coroutine & this ); 39 39 40 static inline void ?{}( coroutine_desc& this) { this{ "Anonymous Coroutine", 0p, 0 }; }41 static inline void ?{}( coroutine_desc& this, size_t stackSize) { this{ "Anonymous Coroutine", 0p, stackSize }; }42 static inline void ?{}( coroutine_desc& this, void * storage, size_t storageSize ) { this{ "Anonymous Coroutine", storage, storageSize }; }43 static inline void ?{}( coroutine_desc& this, const char name[]) { this{ name, 0p, 0 }; }44 static inline void ?{}( coroutine_desc& this, const char name[], size_t stackSize ) { this{ name, 0p, stackSize }; }40 static inline void ?{}( $coroutine & this) { this{ "Anonymous Coroutine", 0p, 0 }; } 41 static inline void ?{}( $coroutine & this, size_t stackSize) { this{ "Anonymous Coroutine", 0p, stackSize }; } 42 static inline void ?{}( $coroutine & this, void * storage, size_t storageSize ) { this{ "Anonymous Coroutine", storage, storageSize }; } 43 static inline void ?{}( $coroutine & this, const char name[]) { this{ name, 0p, 0 }; } 44 static inline void ?{}( $coroutine & this, const char name[], size_t stackSize ) { this{ name, 0p, stackSize }; } 45 45 46 46 //----------------------------------------------------------------------------- … … 54 54 void prime(T & cor); 55 55 56 static inline struct coroutine_desc* active_coroutine() { return TL_GET( this_thread )->curr_cor; }56 static inline struct $coroutine * active_coroutine() { return TL_GET( this_thread )->curr_cor; } 57 57 58 58 //----------------------------------------------------------------------------- … … 64 64 65 65 forall(dtype T) 66 void __cfactx_start(void (*main)(T &), struct coroutine_desc* cor, T & this, void (*invoke)(void (*main)(void *), void *));66 void __cfactx_start(void (*main)(T &), struct $coroutine * cor, T & this, void (*invoke)(void (*main)(void *), void *)); 67 67 68 extern void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct coroutine_desc*) __attribute__ ((__noreturn__));68 extern void __cfactx_coroutine_unwind(struct _Unwind_Exception * storage, struct $coroutine *) __attribute__ ((__noreturn__)); 69 69 70 70 extern void __cfactx_switch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("__cfactx_switch"); … … 73 73 // Private wrappers for context switch and stack creation 74 74 // Wrapper for co 75 static inline void CoroutineCtxSwitch( coroutine_desc * src, coroutine_desc* dst ) __attribute__((nonnull (1, 2))) {75 static inline void $ctx_switch( $coroutine * src, $coroutine * dst ) __attribute__((nonnull (1, 2))) { 76 76 // set state of current coroutine to inactive 77 77 src->state = src->state == Halted ? Halted : Inactive; … … 102 102 // will also migrate which means this value will 103 103 // stay in syn with the TLS 104 coroutine_desc* src = TL_GET( this_thread )->curr_cor;104 $coroutine * src = TL_GET( this_thread )->curr_cor; 105 105 106 106 assertf( src->last != 0, … … 113 113 src->name, src, src->last->name, src->last ); 114 114 115 CoroutineCtxSwitch( src, src->last );115 $ctx_switch( src, src->last ); 116 116 } 117 117 … … 124 124 // will also migrate which means this value will 125 125 // stay in syn with the TLS 126 coroutine_desc* src = TL_GET( this_thread )->curr_cor;127 coroutine_desc* dst = get_coroutine(cor);126 $coroutine * src = TL_GET( this_thread )->curr_cor; 127 $coroutine * dst = get_coroutine(cor); 128 128 129 129 if( unlikely(dst->context.SP == 0p) ) { … … 147 147 148 148 // always done for performance testing 149 CoroutineCtxSwitch( src, dst );149 $ctx_switch( src, dst ); 150 150 151 151 return cor; 152 152 } 153 153 154 static inline void resume( coroutine_desc* dst ) __attribute__((nonnull (1))) {154 static inline void resume( $coroutine * dst ) __attribute__((nonnull (1))) { 155 155 // optimization : read TLS once and reuse it 156 156 // Safety note: this is preemption safe since if … … 158 158 // will also migrate which means this value will 159 159 // stay in syn with the TLS 160 coroutine_desc* src = TL_GET( this_thread )->curr_cor;160 $coroutine * src = TL_GET( this_thread )->curr_cor; 161 161 162 162 // not resuming self ? … … 172 172 173 173 // always done for performance testing 174 CoroutineCtxSwitch( src, dst );174 $ctx_switch( src, dst ); 175 175 } 176 176
Note: See TracChangeset
for help on using the changeset viewer.