Changeset d3a804f5 for src/libcfa/concurrency/threads.c
- Timestamp:
- Feb 14, 2017, 1:19:28 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 97d246d
- Parents:
- f923b5f (diff), eafb094 (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
-
src/libcfa/concurrency/threads.c
rf923b5f rd3a804f5 17 17 #include "threads" 18 18 19 #include "kernel "19 #include "kernel_private.h" 20 20 #include "libhdr.h" 21 21 … … 24 24 25 25 extern "C" { 26 #include <fenv.h> 26 27 #include <stddef.h> 27 28 } … … 43 44 (&this->c){}; 44 45 this->c.name = "Anonymous Coroutine"; 45 (&this-> lock){};46 (&this->terminated){}; 46 47 this->next = NULL; 47 48 } … … 71 72 //----------------------------------------------------------------------------- 72 73 // Starting and stopping threads 73 extern "C" {74 forall(dtype T | is_thread(T))75 void CtxInvokeThread(T * this);76 }77 78 extern void thread_schedule( thread * );79 80 74 forall( dtype T | is_thread(T) ) 81 75 void start( T* this ) { … … 91 85 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); 92 86 93 LIB_DEBUG_PRINTF("Thread started : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 94 95 thread_schedule(thrd_h); 87 ScheduleThread(thrd_h); 96 88 } 97 89 98 90 forall( dtype T | is_thread(T) ) 99 91 void stop( T* this ) { 100 thread* thrd = get_thread(this); 101 if( thrd->c.notHalted ) { 102 lock( &thrd->lock ); 103 } 92 wait( & get_thread(this)->terminated ); 104 93 } 105 94 106 95 void yield( void ) { 107 thread_schedule( this_thread() ); 108 suspend(); 96 ScheduleInternal( get_this_processor()->current_thread ); 109 97 } 110 98 111 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 112 105 dst->last = src; 113 106 114 // set state of current coroutine to inactive 115 src->state = Inactive; 116 117 // set new coroutine that task is executing 107 // set new coroutine that the processor is executing 108 // and context switch to it 118 109 get_this_processor()->current_coroutine = dst; 119 120 // context switch to specified coroutine121 110 CtxSwitch( src->stack.context, dst->stack.context ); 122 // when CtxSwitch returns we are back in the src coroutine111 get_this_processor()->current_coroutine = src; 123 112 124 113 // set state of new coroutine to active 114 dst->state = Inactive; 125 115 src->state = Active; 126 116 } … … 130 120 extern "C" { 131 121 void __thread_signal_termination( thread * this ) { 132 this->c.state = Halt ;133 this->c.notHalted = false;134 unlock( &this->lock );122 this->c.state = Halted; 123 LIB_DEBUG_PRINTF("Thread end : %p\n", this); 124 signal( &this->terminated ); 135 125 } 136 126 }
Note:
See TracChangeset
for help on using the changeset viewer.