Changeset 83a071f9 for src/libcfa/concurrency
- Timestamp:
- Aug 11, 2017, 10:10:26 AM (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:
- fd344aa
- Parents:
- 8499c707
- Location:
- src/libcfa/concurrency
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/coroutine
r8499c707 r83a071f9 26 26 // Anything that is resumed is a coroutine. 27 27 trait is_coroutine(dtype T) { 28 void main(T *this);29 coroutine_desc * get_coroutine(T *this);28 void main(T & this); 29 coroutine_desc * get_coroutine(T & this); 30 30 }; 31 31 32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X * this) { return &this->__cor; } void main(X*this)32 #define DECL_COROUTINE(X) static inline coroutine_desc* get_coroutine(X& this) { return &this.__cor; } void main(X& this) 33 33 34 34 //----------------------------------------------------------------------------- … … 45 45 46 46 forall(dtype T | is_coroutine(T)) 47 static inline void resume(T *cor);47 static inline void resume(T & cor); 48 48 49 49 forall(dtype T | is_coroutine(T)) 50 void prime(T *cor);50 void prime(T & cor); 51 51 52 52 //----------------------------------------------------------------------------- … … 87 87 // Resume implementation inlined for performance 88 88 forall(dtype T | is_coroutine(T)) 89 static inline void resume(T *cor) {89 static inline void resume(T & cor) { 90 90 coroutine_desc * src = this_coroutine; // optimization 91 91 coroutine_desc * dst = get_coroutine(cor); … … 93 93 if( unlikely(!dst->stack.base) ) { 94 94 create_stack(&dst->stack, dst->stack.size); 95 CtxStart( cor, CtxInvokeCoroutine);95 CtxStart(&cor, CtxInvokeCoroutine); 96 96 } 97 97 -
src/libcfa/concurrency/coroutine.c
r8499c707 r83a071f9 93 93 // Not inline since only ever called once per coroutine 94 94 forall(dtype T | is_coroutine(T)) 95 void prime(T *cor) {95 void prime(T& cor) { 96 96 coroutine_desc* this = get_coroutine(cor); 97 97 assert(this->state == Start); -
src/libcfa/concurrency/kernel.c
r8499c707 r83a071f9 139 139 } 140 140 141 void ?{}(processor & this, cluster * cltr, processorCtx_t *runner) {141 void ?{}(processor & this, cluster * cltr, processorCtx_t & runner) { 142 142 this.cltr = cltr; 143 143 (this.terminated){ 0 }; … … 148 148 this.kernel_thread = pthread_self(); 149 149 150 this.runner = runner;151 LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", runner);152 (*runner){ &this };150 this.runner = &runner; 151 LIB_DEBUG_PRINT_SAFE("Kernel : constructing system processor context %p\n", &runner); 152 runner{ &this }; 153 153 } 154 154 155 155 LIB_DEBUG_DO( bool validate( alarm_list_t * this ); ) 156 156 157 void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t *runner) {157 void ?{}(system_proc_t & this, cluster * cltr, processorCtx_t & runner) { 158 158 (this.alarms){}; 159 159 (this.alarm_lock){}; … … 187 187 //============================================================================================= 188 188 //Main of the processor contexts 189 void main(processorCtx_t *runner) {190 processor * this = runner ->proc;189 void main(processorCtx_t & runner) { 190 processor * this = runner.proc; 191 191 192 192 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); … … 233 233 // from the processor coroutine to the target thread 234 234 void runThread(processor * this, thread_desc * dst) { 235 coroutine_desc * proc_cor = get_coroutine( this->runner);235 coroutine_desc * proc_cor = get_coroutine(*this->runner); 236 236 coroutine_desc * thrd_cor = get_coroutine(dst); 237 237 … … 315 315 // appropriate stack. 316 316 proc_cor_storage.__cor.state = Active; 317 main( &proc_cor_storage );317 main( proc_cor_storage ); 318 318 proc_cor_storage.__cor.state = Halted; 319 319 … … 455 455 mainThread = (thread_desc *)&mainThreadStorage; 456 456 current_stack_info_t info; 457 mainThread{ &info };457 (*mainThread){ &info }; 458 458 459 459 LIB_DEBUG_PRINT_SAFE("Kernel : Main thread ready\n"); … … 461 461 // Initialize the system cluster 462 462 systemCluster = (cluster *)&systemClusterStorage; 463 systemCluster{};463 (*systemCluster){}; 464 464 465 465 LIB_DEBUG_PRINT_SAFE("Kernel : System cluster ready\n"); … … 468 468 // (the coroutine that contains the processing control flow) 469 469 systemProcessor = (system_proc_t *)&systemProcessorStorage; 470 (*systemProcessor){ systemCluster, (processorCtx_t *)&systemProcessorCtxStorage };470 (*systemProcessor){ systemCluster, *(processorCtx_t *)&systemProcessorCtxStorage }; 471 471 472 472 // Add the main thread to the ready queue … … 486 486 // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that 487 487 // mainThread is on the ready queue when this call is made. 488 resume( systemProcessor->proc.runner );488 resume( *systemProcessor->proc.runner ); 489 489 490 490 … … 514 514 // Destroy the system processor and its context in reverse order of construction 515 515 // These were manually constructed so we need manually destroy them 516 ^( systemProcessor->proc.runner){};516 ^(*systemProcessor->proc.runner){}; 517 517 ^(systemProcessor){}; 518 518 -
src/libcfa/concurrency/thread
r8499c707 r83a071f9 30 30 trait is_thread(dtype T) { 31 31 void ^?{}(T& mutex this); 32 void main(T *this);33 thread_desc* get_thread(T *this);32 void main(T& this); 33 thread_desc* get_thread(T& this); 34 34 }; 35 35 36 #define DECL_THREAD(X) thread_desc* get_thread(X * this) { return &this->__thrd; } void main(X*this)36 #define DECL_THREAD(X) thread_desc* get_thread(X& this) { return &this.__thrd; } void main(X& this) 37 37 38 38 forall( dtype T | is_thread(T) ) 39 static inline coroutine_desc* get_coroutine(T *this) {39 static inline coroutine_desc* get_coroutine(T & this) { 40 40 return &get_thread(this)->cor; 41 41 } 42 42 43 43 forall( dtype T | is_thread(T) ) 44 static inline monitor_desc* get_monitor(T *this) {44 static inline monitor_desc* get_monitor(T & this) { 45 45 return &get_thread(this)->mon; 46 46 } … … 57 57 58 58 forall( dtype T | is_thread(T) ) 59 void __thrd_start( T *this );59 void __thrd_start( T & this ); 60 60 61 61 //----------------------------------------------------------------------------- -
src/libcfa/concurrency/thread.c
r8499c707 r83a071f9 51 51 void ?{}( scoped(T)& this ) { 52 52 (this.handle){}; 53 __thrd_start( &this.handle);53 __thrd_start(this.handle); 54 54 } 55 55 … … 57 57 void ?{}( scoped(T)& this, P params ) { 58 58 (this.handle){ params }; 59 __thrd_start( &this.handle);59 __thrd_start(this.handle); 60 60 } 61 61 … … 68 68 // Starting and stopping threads 69 69 forall( dtype T | is_thread(T) ) 70 void __thrd_start( T *this ) {70 void __thrd_start( T& this ) { 71 71 coroutine_desc* thrd_c = get_coroutine(this); 72 72 thread_desc* thrd_h = get_thread (this); … … 78 78 create_stack(&thrd_c->stack, thrd_c->stack.size); 79 79 this_coroutine = thrd_c; 80 CtxStart( this, CtxInvokeThread);80 CtxStart(&this, CtxInvokeThread); 81 81 assert( thrd_c->last->stack.context ); 82 82 CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
Note: See TracChangeset
for help on using the changeset viewer.