- File:
-
- 1 edited
-
src/libcfa/concurrency/threads.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/threads.c
r8fcbb4c ree897e4b 17 17 #include "threads" 18 18 19 #include "kernel "19 #include "kernel_private.h" 20 20 #include "libhdr.h" 21 21 … … 44 44 (&this->c){}; 45 45 this->c.name = "Anonymous Coroutine"; 46 (&this-> lock){};46 (&this->terminated){}; 47 47 this->next = NULL; 48 48 } … … 72 72 //----------------------------------------------------------------------------- 73 73 // Starting and stopping threads 74 extern "C" {75 forall(dtype T | is_thread(T))76 void CtxInvokeThread(T * this);77 }78 79 extern void thread_schedule( thread * );80 81 74 forall( dtype T | is_thread(T) ) 82 75 void start( T* this ) { … … 92 85 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); 93 86 94 fenv_t envp; 95 fegetenv( &envp ); 96 LIB_DEBUG_PRINTF("Thread : mxcsr %x\n", envp.__mxcsr); 97 LIB_DEBUG_PRINTF("Thread started : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 98 99 thread_schedule(thrd_h); 87 ScheduleThread(thrd_h); 100 88 } 101 89 102 90 forall( dtype T | is_thread(T) ) 103 91 void stop( T* this ) { 104 thread* thrd = get_thread(this); 105 if( thrd->c.notHalted ) { 106 lock( &thrd->lock ); 107 } 92 wait( & get_thread(this)->terminated ); 108 93 } 109 94 110 95 void yield( void ) { 111 get_this_processor()->thread_action = Reschedule; 112 suspend(); 96 ScheduleInternal( get_this_processor()->current_thread ); 113 97 } 114 98 115 99 void ThreadCtxSwitch(coroutine* src, coroutine* dst) { 100 // set state of current coroutine to inactive 101 src->state = Inactive; 102 dst->state = Active; 103 104 //update the last resumer 116 105 dst->last = src; 117 106 118 // set state of current coroutine to inactive 119 src->state = Inactive; 120 121 // set new coroutine that task is executing 107 // set new coroutine that the processor is executing 108 // and context switch to it 122 109 get_this_processor()->current_coroutine = dst; 123 124 // context switch to specified coroutine125 110 CtxSwitch( src->stack.context, dst->stack.context ); 126 // when CtxSwitch returns we are back in the src coroutine111 get_this_processor()->current_coroutine = src; 127 112 128 113 // set state of new coroutine to active 114 dst->state = Inactive; 129 115 src->state = Active; 130 116 } … … 134 120 extern "C" { 135 121 void __thread_signal_termination( thread * this ) { 136 this->c.state = Halt ;137 this->c.notHalted = false;138 unlock( &this->lock );122 this->c.state = Halted; 123 LIB_DEBUG_PRINTF("Thread end : %p\n", this); 124 signal( &this->terminated ); 139 125 } 140 126 }
Note:
See TracChangeset
for help on using the changeset viewer.