Changeset b4d65c7 for src/libcfa/concurrency/threads.c
- Timestamp:
- Feb 6, 2017, 4:19:53 PM (7 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:
- 424931d, fe26fbf
- Parents:
- c0aa336 (diff), 6a5f0e7 (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
rc0aa336 rb4d65c7 31 31 //----------------------------------------------------------------------------- 32 32 // Forward declarations 33 forall( dtype T | sized(T) |is_thread(T) )33 forall( dtype T | is_thread(T) ) 34 34 void start( T* this ); 35 35 36 forall( dtype T | sized(T) |is_thread(T) )36 forall( dtype T | is_thread(T) ) 37 37 void stop( T* this ); 38 38 … … 78 78 extern void thread_schedule( thread * ); 79 79 80 forall( dtype T | sized(T) |is_thread(T) )80 forall( dtype T | is_thread(T) ) 81 81 void start( T* this ) { 82 82 coroutine* thrd_c = get_coroutine(this); … … 85 85 get_this_processor()->current_coroutine = thrd_c; 86 86 87 // LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", handle, thrd_c, thrd_h);87 LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 88 88 89 89 create_stack(&thrd_c->stack, thrd_c->stack.size); … … 91 91 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context ); 92 92 93 LIB_DEBUG_PRINTF("Thread started : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 94 93 95 thread_schedule(thrd_h); 94 96 } 95 97 96 forall( dtype T | sized(T) |is_thread(T) )98 forall( dtype T | is_thread(T) ) 97 99 void stop( T* this ) { 98 100 thread* thrd = get_thread(this); … … 102 104 } 103 105 104 void signal_termination( thread * this ) {105 this->c.state = Halt;106 this->c.notHalted = false;107 unlock( &this->lock );108 }109 110 106 void yield( void ) { 111 107 thread_schedule( this_thread() ); 112 108 suspend(); 109 } 110 111 void ThreadCtxSwitch(coroutine* src, coroutine* dst) { 112 dst->last = src; 113 114 // set state of current coroutine to inactive 115 src->state = Inactive; 116 117 // set new coroutine that task is executing 118 get_this_processor()->current_coroutine = dst; 119 120 // context switch to specified coroutine 121 CtxSwitch( src->stack.context, dst->stack.context ); 122 // when CtxSwitch returns we are back in the src coroutine 123 124 // set state of new coroutine to active 125 src->state = Active; 126 } 127 128 // C Helper to signal the termination of a thread 129 // Used in invoke.c 130 extern "C" { 131 void __thread_signal_termination( thread * this ) { 132 this->c.state = Halt; 133 this->c.notHalted = false; 134 unlock( &this->lock ); 135 } 113 136 } 114 137
Note: See TracChangeset
for help on using the changeset viewer.