Changeset 63364d8 for libcfa/src/concurrency
- Timestamp:
- May 9, 2019, 4:47:28 PM (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:
- b038fe4
- Parents:
- f019069
- Location:
- libcfa/src/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/CtxSwitch-x86_64.S
rf019069 r63364d8 80 80 81 81 //----------------------------------------------------------------------------- 82 // Part of a 2 part context switch routine, use with CtxRet, stores the current context and then makes a function call83 .text84 .align 285 .globl CtxStore86 .type CtxStore, @function87 CtxStore:88 89 // Save volatile registers on the stack.90 91 pushq %r1592 pushq %r1493 pushq %r1394 pushq %r1295 pushq %rbx96 97 // Save old context in the "from" area.98 99 movq %rsp,SP_OFFSET(%rdi)100 movq %rbp,FP_OFFSET(%rdi)101 102 mfence103 104 // Don't load a new context, directly jump to the desired function105 #if defined(PIC)106 call __suspend_callback@plt107 #else108 call __suspend_callback109 #endif110 .size CtxStore, .-CtxStore111 112 //-----------------------------------------------------------------------------113 // Part of a 2 part context switch routine, use with CtxStore, context switches to the desired target without saving the current context114 .text115 .align 2116 .globl CtxRet117 .type CtxRet, @function118 CtxRet:119 // Load new context from the "to" area.120 121 movq SP_OFFSET(%rdi),%rsp122 movq FP_OFFSET(%rdi),%rbp123 124 // Load volatile registers from the stack.125 126 popq %rbx127 popq %r12128 popq %r13129 popq %r14130 popq %r15131 132 // Return to thread.133 134 ret135 .size CtxRet, .-CtxRet136 137 138 //-----------------------------------------------------------------------------139 82 // Stub used to create new stacks which are ready to be context switched to 140 83 .text -
libcfa/src/concurrency/coroutine.cfa
rf019069 r63364d8 205 205 CoroutineCtxSwitch( src, starter ); 206 206 } 207 208 __attribute__((noreturn)) void __suspend_callback( struct __stack_context_t *, fptr_t call ) {209 call();210 211 coroutine_desc * src = TL_GET( this_thread )->curr_cor;212 // set state of current coroutine to inactive213 src->state = src->state == Halted ? Halted : Inactive;214 215 TL_GET( this_thread )->curr_cor = src->last;216 217 // context switch to specified coroutine218 assert( src->last->context.SP );219 CtxRet( &src->last->context );220 221 abort();222 }223 207 } 224 208 -
libcfa/src/concurrency/coroutine.hfa
rf019069 r63364d8 68 68 69 69 extern void CtxSwitch( struct __stack_context_t * from, struct __stack_context_t * to ) asm ("CtxSwitch"); 70 extern void CtxStore ( struct __stack_context_t * from, fptr_t callback ) asm ("CtxStore");71 70 } 72 71 … … 171 170 } 172 171 173 __attribute__((noreturn)) void __suspend_callback(void *, fptr_t call);174 175 static inline void suspend_then(fptr_t call) {176 // optimization : read TLS once and reuse it177 // Safety note: this is preemption safe since if178 // preemption occurs after this line, the pointer179 // will also migrate which means this value will180 // stay in syn with the TLS181 coroutine_desc * src = TL_GET( this_thread )->curr_cor;182 183 assertf( src->last != 0,184 "Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"185 "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",186 src->name, src );187 assertf( src->last->state != Halted,188 "Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"189 "Possible cause is terminated coroutine's main routine has already returned.",190 src->name, src, src->last->name, src->last );191 192 src->state = PreInactive;193 194 // context switch to specified coroutine195 assert( src->context.SP );196 197 CtxStore( &src->context, call );198 // when CtxStore returns we are back in the src coroutine199 200 // set state of new coroutine to active201 src->state = Active;202 203 if( unlikely(src->cancellation != NULL) ) {204 _CtxCoroutine_Unwind(src->cancellation, src);205 }206 207 return;208 }209 210 172 // Local Variables: // 211 173 // mode: c // -
libcfa/src/concurrency/invoke.h
rf019069 r63364d8 93 93 }; 94 94 95 enum coroutine_state { Halted, Start, Inactive, Active, Primed , PreInactive};95 enum coroutine_state { Halted, Start, Inactive, Active, Primed }; 96 96 97 97 struct coroutine_desc {
Note: See TracChangeset
for help on using the changeset viewer.