- File:
-
- 1 edited
-
libcfa/src/concurrency/thread.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/thread.cfa
re8e457e r58b6d1b 31 31 // Thread ctors and dtors 32 32 void ?{}(thread_desc & this, const char * const name, cluster & cl, void * storage, size_t storageSize ) with( this ) { 33 context{ NULL, NULL };34 33 self_cor{ name, storage, storageSize }; 35 state = Start;34 verify(&self_cor); 36 35 curr_cor = &self_cor; 37 36 self_mon.owner = &this; … … 74 73 forall( dtype T | is_thread(T) ) 75 74 void __thrd_start( T& this ) { 76 thread_desc * this_thrd = get_thread(this); 77 thread_desc * curr_thrd = TL_GET( this_thread ); 75 coroutine_desc* thrd_c = get_coroutine(this); 76 thread_desc * thrd_h = get_thread (this); 77 thrd_c->last = TL_GET( this_coroutine ); 78 79 // __cfaabi_dbg_print_safe("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 78 80 79 81 disable_interrupts(); 82 create_stack(&thrd_c->stack, thrd_c->stack.size); 83 kernelTLS.this_coroutine = thrd_c; 80 84 CtxStart(&this, CtxInvokeThread); 81 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; 82 verify( this_thrd->context.SP ); 83 CtxSwitch( &curr_thrd->context, &this_thrd->context ); 85 assert( thrd_c->last->stack.context ); 86 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); 84 87 85 ScheduleThread(th is_thrd);88 ScheduleThread(thrd_h); 86 89 enable_interrupts( __cfaabi_dbg_ctx ); 87 90 } … … 89 92 extern "C" { 90 93 // KERNEL ONLY 91 void __finish_creation(thread_desc * this) { 92 // set new coroutine that the processor is executing 93 // and context switch to it 94 verify( kernelTLS.this_thread != this ); 95 verify( kernelTLS.this_thread->context.SP ); 96 CtxSwitch( &this->context, &kernelTLS.this_thread->context ); 94 void __finish_creation(void) { 95 coroutine_desc* thrd_c = kernelTLS.this_coroutine; 96 ThreadCtxSwitch( thrd_c, thrd_c->last ); 97 97 } 98 98 } … … 112 112 } 113 113 114 // KERNEL ONLY 115 void ThreadCtxSwitch(coroutine_desc* src, coroutine_desc* dst) { 116 // set state of current coroutine to inactive 117 src->state = src->state == Halted ? Halted : Inactive; 118 dst->state = Active; 119 120 // set new coroutine that the processor is executing 121 // and context switch to it 122 kernelTLS.this_coroutine = dst; 123 assert( src->stack.context ); 124 CtxSwitch( src->stack.context, dst->stack.context ); 125 kernelTLS.this_coroutine = src; 126 127 // set state of new coroutine to active 128 dst->state = dst->state == Halted ? Halted : Inactive; 129 src->state = Active; 130 } 131 114 132 // Local Variables: // 115 133 // mode: c //
Note:
See TracChangeset
for help on using the changeset viewer.