Changeset 348006f for src/libcfa
- Timestamp:
- Mar 15, 2017, 4:20:26 PM (8 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:
- 29f44a74
- Parents:
- 84c52a8
- Location:
- src/libcfa/concurrency
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/libcfa/concurrency/invoke.c ¶
r84c52a8 r348006f 29 29 30 30 extern void __suspend_internal(void); 31 extern void __thread_signal_termination(struct thread *);31 extern void __thread_signal_termination(struct thread_desc*); 32 32 33 33 void CtxInvokeCoroutine( … … 57 57 void CtxInvokeThread( 58 58 void (*main)(void *), 59 struct thread *(*get_thread)(void *),59 struct thread_desc *(*get_thread)(void *), 60 60 void *this 61 61 ) { 62 62 __suspend_internal(); 63 63 64 struct thread * thrd = get_thread( this );64 struct thread_desc* thrd = get_thread( this ); 65 65 struct coroutine_desc* cor = &thrd->c; 66 66 cor->state = Active; -
TabularUnified src/libcfa/concurrency/invoke.h ¶
r84c52a8 r348006f 35 35 36 36 struct simple_thread_list { 37 struct thread * head;38 struct thread ** tail;37 struct thread_desc * head; 38 struct thread_desc ** tail; 39 39 }; 40 40 … … 48 48 extern "Cforall" { 49 49 void ?{}( struct simple_thread_list * ); 50 void append( struct simple_thread_list *, struct thread * );51 struct thread * pop_head( struct simple_thread_list * );50 void append( struct simple_thread_list *, struct thread_desc * ); 51 struct thread_desc * pop_head( struct simple_thread_list * ); 52 52 53 53 void ?{}(spinlock * this); … … 80 80 }; 81 81 82 struct thread {82 struct thread_desc { 83 83 struct coroutine_desc c; // coroutine body used to store context 84 84 struct signal_once terminated; // indicate if execuation state is not halted 85 struct thread * next; // instrusive link field for threads85 struct thread_desc * next; // instrusive link field for threads 86 86 }; 87 87 -
TabularUnified src/libcfa/concurrency/kernel ¶
r84c52a8 r348006f 49 49 struct FinishAction { 50 50 FinishOpCode action_code; 51 thread * thrd;51 thread_desc * thrd; 52 52 spinlock * lock; 53 53 }; … … 63 63 cluster * cltr; 64 64 coroutine_desc * current_coroutine; 65 thread * current_thread;65 thread_desc * current_thread; 66 66 pthread_t kernel_thread; 67 67 -
TabularUnified src/libcfa/concurrency/kernel.c ¶
r84c52a8 r348006f 43 43 KERNEL_STORAGE(cluster, systemCluster); 44 44 KERNEL_STORAGE(processor, systemProcessor); 45 KERNEL_STORAGE(thread , mainThread);45 KERNEL_STORAGE(thread_desc, mainThread); 46 46 KERNEL_STORAGE(machine_context_t, mainThread_context); 47 47 48 48 cluster * systemCluster; 49 49 processor * systemProcessor; 50 thread * mainThread;50 thread_desc * mainThread; 51 51 52 52 //----------------------------------------------------------------------------- … … 59 59 } 60 60 61 thread * this_thread(void) {61 thread_desc * this_thread(void) { 62 62 return this_processor->current_thread; 63 63 } … … 106 106 } 107 107 108 void ?{}( thread * this, current_stack_info_t * info) {108 void ?{}( thread_desc * this, current_stack_info_t * info) { 109 109 (&this->c){ info }; 110 110 } … … 175 175 LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this); 176 176 177 thread * readyThread = NULL;177 thread_desc * readyThread = NULL; 178 178 for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ ) 179 179 { … … 202 202 // runThread runs a thread by context switching 203 203 // from the processor coroutine to the target thread 204 void runThread(processor * this, thread * dst) {204 void runThread(processor * this, thread_desc * dst) { 205 205 coroutine_desc * proc_cor = get_coroutine(this->runner); 206 206 coroutine_desc * thrd_cor = get_coroutine(dst); … … 293 293 //----------------------------------------------------------------------------- 294 294 // Scheduler routines 295 void ScheduleThread( thread * thrd ) {295 void ScheduleThread( thread_desc * thrd ) { 296 296 assertf( thrd->next == NULL, "Expected null got %p", thrd->next ); 297 297 … … 301 301 } 302 302 303 thread * nextThread(cluster * this) {303 thread_desc * nextThread(cluster * this) { 304 304 lock( &this->lock ); 305 thread * head = pop_head( &this->ready_queue );305 thread_desc * head = pop_head( &this->ready_queue ); 306 306 unlock( &this->lock ); 307 307 return head; … … 318 318 } 319 319 320 void ScheduleInternal( thread * thrd ) {320 void ScheduleInternal( thread_desc * thrd ) { 321 321 this_processor->finish.action_code = Schedule; 322 322 this_processor->finish.thrd = thrd; … … 324 324 } 325 325 326 void ScheduleInternal( spinlock * lock, thread * thrd ) {326 void ScheduleInternal( spinlock * lock, thread_desc * thrd ) { 327 327 this_processor->finish.action_code = Release_Schedule; 328 328 this_processor->finish.lock = lock; … … 339 339 // SKULLDUGGERY: the mainThread steals the process main thread 340 340 // which will then be scheduled by the systemProcessor normally 341 mainThread = (thread *)&mainThread_storage;341 mainThread = (thread_desc *)&mainThread_storage; 342 342 current_stack_info_t info; 343 343 mainThread{ &info }; … … 436 436 this->condition = true; 437 437 438 thread * it;438 thread_desc * it; 439 439 while( it = pop_head( &this->blocked) ) { 440 440 ScheduleThread( it ); … … 451 451 } 452 452 453 void append( simple_thread_list * this, thread * t ) {453 void append( simple_thread_list * this, thread_desc * t ) { 454 454 assert(this->tail != NULL); 455 455 *this->tail = t; … … 457 457 } 458 458 459 thread * pop_head( simple_thread_list * this ) {460 thread * head = this->head;459 thread_desc * pop_head( simple_thread_list * this ) { 460 thread_desc * head = this->head; 461 461 if( head ) { 462 462 this->head = head->next; -
TabularUnified src/libcfa/concurrency/kernel_private.h ¶
r84c52a8 r348006f 23 23 //----------------------------------------------------------------------------- 24 24 // Scheduler 25 void ScheduleThread( thread * );26 thread * nextThread(cluster * this);25 void ScheduleThread( thread_desc * ); 26 thread_desc * nextThread(cluster * this); 27 27 28 28 void ScheduleInternal(); 29 29 void ScheduleInternal(spinlock * lock); 30 void ScheduleInternal(thread * thrd);31 void ScheduleInternal(spinlock * lock, thread * thrd);30 void ScheduleInternal(thread_desc * thrd); 31 void ScheduleInternal(spinlock * lock, thread_desc * thrd); 32 32 33 33 //----------------------------------------------------------------------------- … … 42 42 void main(processorCtx_t *); 43 43 void start(processor * this); 44 void runThread(processor * this, thread * dst);44 void runThread(processor * this, thread_desc * dst); 45 45 void finishRunning(processor * this); 46 46 void spin(processor * this, unsigned int * spin_count); -
TabularUnified src/libcfa/concurrency/monitor ¶
r84c52a8 r348006f 24 24 struct monitor_desc { 25 25 spinlock lock; 26 thread * owner;26 thread_desc * owner; 27 27 simple_thread_list entry_queue; 28 28 unsigned int recursion; -
TabularUnified src/libcfa/concurrency/monitor.c ¶
r84c52a8 r348006f 21 21 void enter(monitor_desc * this) { 22 22 lock( &this->lock ); 23 thread * thrd = this_thread();23 thread_desc * thrd = this_thread(); 24 24 25 25 if( !this->owner ) { … … 48 48 lock( &this->lock ); 49 49 50 thread * thrd = this_thread();50 thread_desc * thrd = this_thread(); 51 51 assert( thrd == this->owner ); 52 52 … … 55 55 56 56 //If we left the last level of recursion it means we are changing who owns the monitor 57 thread * new_owner = 0;57 thread_desc * new_owner = 0; 58 58 if( this->recursion == 0) { 59 59 //Get the next thread in the list -
TabularUnified src/libcfa/concurrency/thread ¶
r84c52a8 r348006f 29 29 trait is_thread(dtype T) { 30 30 void main(T* this); 31 thread * get_thread(T* this);31 thread_desc* get_thread(T* this); 32 32 }; 33 33 34 #define DECL_THREAD(X) thread * get_thread(X* this) { return &this->t; } void main(X* this)34 #define DECL_THREAD(X) thread_desc* get_thread(X* this) { return &this->t; } void main(X* this) 35 35 36 36 forall( dtype T | is_thread(T) ) … … 39 39 } 40 40 41 static inline coroutine_desc* get_coroutine(thread * this) {41 static inline coroutine_desc* get_coroutine(thread_desc* this) { 42 42 return &this->c; 43 43 } 44 44 45 thread * this_thread(void);45 thread_desc * this_thread(void); 46 46 47 47 //----------------------------------------------------------------------------- 48 48 // Ctors and dtors 49 void ?{}(thread * this);50 void ^?{}(thread * this);49 void ?{}(thread_desc* this); 50 void ^?{}(thread_desc* this); 51 51 52 52 //----------------------------------------------------------------------------- -
TabularUnified src/libcfa/concurrency/thread.c ¶
r84c52a8 r348006f 41 41 // Thread ctors and dtors 42 42 43 void ?{}(thread * this) {43 void ?{}(thread_desc* this) { 44 44 (&this->c){}; 45 45 this->c.name = "Anonymous Coroutine"; … … 48 48 } 49 49 50 void ^?{}(thread * this) {50 void ^?{}(thread_desc* this) { 51 51 ^(&this->c){}; 52 52 } … … 75 75 void start( T* this ) { 76 76 coroutine_desc* thrd_c = get_coroutine(this); 77 thread * thrd_h = get_thread (this);77 thread_desc* thrd_h = get_thread (this); 78 78 thrd_c->last = this_coroutine(); 79 79 this_processor->current_coroutine = thrd_c; … … 116 116 } 117 117 118 // C Helper to signal the termination of a thread 118 // C Helper to signal the termination of a thread_desc 119 119 // Used in invoke.c 120 120 extern "C" { 121 void __thread_signal_termination( thread * this ) {121 void __thread_signal_termination( thread_desc * this ) { 122 122 this->c.state = Halted; 123 123 LIB_DEBUG_PRINTF("Thread end : %p\n", this);
Note: See TracChangeset
for help on using the changeset viewer.