Changeset b067d9b for libcfa/src/concurrency/coroutine.hfa
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
r7951100 rb067d9b 10 10 // Created On : Mon Nov 28 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 30 18:23:45 201813 // Update Count : 812 // Last Modified On : Fri Jun 21 17:49:39 2019 13 // Update Count : 9 14 14 // 15 15 … … 46 46 //----------------------------------------------------------------------------- 47 47 // Public coroutine API 48 static inline void suspend( );48 static inline void suspend(void); 49 49 50 50 forall(dtype T | is_coroutine(T)) 51 static inline voidresume(T & cor);51 static inline T & resume(T & cor); 52 52 53 53 forall(dtype T | is_coroutine(T)) 54 54 void prime(T & cor); 55 56 static inline struct coroutine_desc * active_coroutine() { return TL_GET( this_thread )->curr_cor; } 55 57 56 58 //----------------------------------------------------------------------------- … … 64 66 forall(dtype T | is_coroutine(T)) 65 67 void CtxStart(T * this, void ( *invoke)(T *)); 68 69 extern void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__)); 70 71 extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch"); 66 72 } 67 73 68 74 // Private wrappers for context switch and stack creation 69 extern void CoroutineCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 70 extern void create_stack( coStack_t * this, unsigned int storageSize ); 75 // Wrapper for co 76 static inline void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 77 // set state of current coroutine to inactive 78 src->state = src->state == Halted ? Halted : Inactive; 79 80 // set new coroutine that task is executing 81 TL_GET( this_thread )->curr_cor = dst; 82 83 // context switch to specified coroutine 84 verify( dst->context.SP ); 85 CtxSwitch( &src->context, &dst->context ); 86 // when CtxSwitch returns we are back in the src coroutine 87 88 // set state of new coroutine to active 89 src->state = Active; 90 91 if( unlikely(src->cancellation != NULL) ) { 92 _CtxCoroutine_Unwind(src->cancellation, src); 93 } 94 } 95 96 extern void __stack_prepare ( __stack_info_t * this, size_t size /* ignored if storage already allocated */); 71 97 72 98 // Suspend implementation inlined for performance 73 static inline void suspend( ) {99 static inline void suspend(void) { 74 100 // optimization : read TLS once and reuse it 75 101 // Safety note: this is preemption safe since if … … 77 103 // will also migrate which means this value will 78 104 // stay in syn with the TLS 79 coroutine_desc * src = TL_GET( this_ coroutine );105 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 80 106 81 107 assertf( src->last != 0, … … 93 119 // Resume implementation inlined for performance 94 120 forall(dtype T | is_coroutine(T)) 95 static inline voidresume(T & cor) {121 static inline T & resume(T & cor) { 96 122 // optimization : read TLS once and reuse it 97 123 // Safety note: this is preemption safe since if … … 99 125 // will also migrate which means this value will 100 126 // stay in syn with the TLS 101 coroutine_desc * src = TL_GET( this_ coroutine );127 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 102 128 coroutine_desc * dst = get_coroutine(cor); 103 129 104 if( unlikely( !dst->stack.base) ) {105 create_stack(&dst->stack, dst->stack.size);130 if( unlikely(dst->context.SP == NULL) ) { 131 __stack_prepare(&dst->stack, 65000); 106 132 CtxStart(&cor, CtxInvokeCoroutine); 107 133 } … … 121 147 // always done for performance testing 122 148 CoroutineCtxSwitch( src, dst ); 149 150 return cor; 123 151 } 124 152 … … 129 157 // will also migrate which means this value will 130 158 // stay in syn with the TLS 131 coroutine_desc * src = TL_GET( this_ coroutine );159 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 132 160 133 161 // not resuming self ?
Note:
See TracChangeset
for help on using the changeset viewer.