Changeset 933f32f for libcfa/src/concurrency/coroutine.hfa
- Timestamp:
- May 24, 2019, 10:19:41 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d908563
- Parents:
- 6a9d4b4 (diff), 292642a (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 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/coroutine.hfa
r6a9d4b4 r933f32f 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)) … … 64 64 forall(dtype T | is_coroutine(T)) 65 65 void CtxStart(T * this, void ( *invoke)(T *)); 66 67 extern void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__)); 68 69 extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch"); 66 70 } 67 71 68 72 // 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 ); 73 // Wrapper for co 74 static inline void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 75 // set state of current coroutine to inactive 76 src->state = src->state == Halted ? Halted : Inactive; 77 78 // set new coroutine that task is executing 79 TL_GET( this_thread )->curr_cor = dst; 80 81 // context switch to specified coroutine 82 verify( dst->context.SP ); 83 CtxSwitch( &src->context, &dst->context ); 84 // when CtxSwitch returns we are back in the src coroutine 85 86 // set state of new coroutine to active 87 src->state = Active; 88 89 if( unlikely(src->cancellation != NULL) ) { 90 _CtxCoroutine_Unwind(src->cancellation, src); 91 } 92 } 93 94 extern void __stack_prepare ( __stack_info_t * this, size_t size /* ignored if storage already allocated */); 71 95 72 96 // Suspend implementation inlined for performance 73 static inline void suspend( ) {97 static inline void suspend(void) { 74 98 // optimization : read TLS once and reuse it 75 99 // Safety note: this is preemption safe since if … … 77 101 // will also migrate which means this value will 78 102 // stay in syn with the TLS 79 coroutine_desc * src = TL_GET( this_ coroutine );103 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 80 104 81 105 assertf( src->last != 0, … … 93 117 // Resume implementation inlined for performance 94 118 forall(dtype T | is_coroutine(T)) 95 static inline voidresume(T & cor) {119 static inline T & resume(T & cor) { 96 120 // optimization : read TLS once and reuse it 97 121 // Safety note: this is preemption safe since if … … 99 123 // will also migrate which means this value will 100 124 // stay in syn with the TLS 101 coroutine_desc * src = TL_GET( this_ coroutine );125 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 102 126 coroutine_desc * dst = get_coroutine(cor); 103 127 104 if( unlikely( !dst->stack.base) ) {105 create_stack(&dst->stack, dst->stack.size);128 if( unlikely(dst->context.SP == NULL) ) { 129 __stack_prepare(&dst->stack, 65000); 106 130 CtxStart(&cor, CtxInvokeCoroutine); 107 131 } … … 121 145 // always done for performance testing 122 146 CoroutineCtxSwitch( src, dst ); 147 148 return cor; 123 149 } 124 150 … … 129 155 // will also migrate which means this value will 130 156 // stay in syn with the TLS 131 coroutine_desc * src = TL_GET( this_ coroutine );157 coroutine_desc * src = TL_GET( this_thread )->curr_cor; 132 158 133 159 // not resuming self ?
Note:
See TracChangeset
for help on using the changeset viewer.