Changeset bdeba0b for src/libcfa/concurrency/kernel.c
- Timestamp:
- Jul 6, 2017, 4:18:43 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:
- 955d27e9
- Parents:
- b877fa8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rb877fa8 rbdeba0b 129 129 void ?{}(processor * this, cluster * cltr) { 130 130 this->cltr = cltr; 131 (&this->terminated){ };131 (&this->terminated){ 0 }; 132 132 this->is_terminated = false; 133 133 this->preemption_alarm = NULL; … … 140 140 void ?{}(processor * this, cluster * cltr, processorCtx_t * runner) { 141 141 this->cltr = cltr; 142 (&this->terminated){ };142 (&this->terminated){ 0 }; 143 143 this->is_terminated = false; 144 144 this->preemption_alarm = NULL; … … 168 168 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this); 169 169 this->is_terminated = true; 170 wait( &this->terminated ); 170 P( &this->terminated ); 171 pthread_join( this->kernel_thread, NULL ); 171 172 } 172 173 } … … 223 224 } 224 225 225 signal( &this->terminated ); 226 V( &this->terminated ); 227 226 228 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this); 227 229 } … … 607 609 } 608 610 609 void ?{}( signal_once * this) {610 this->cond = false;611 } 612 void ^?{}( signal_once * this ) { 613 614 }615 616 void wait( signal_once * this) {611 void ?{}( semaphore * this, int count = 1 ) { 612 (&this->lock){}; 613 this->count = count; 614 (&this->waiting){}; 615 } 616 void ^?{}(semaphore * this) {} 617 618 void P(semaphore * this) { 617 619 lock( &this->lock DEBUG_CTX2 ); 618 if( !this->cond ) { 619 append( &this->blocked, (thread_desc*)this_thread ); 620 this->count -= 1; 621 if ( this->count < 0 ) { 622 // queue current task 623 append( &this->waiting, (thread_desc *)this_thread ); 624 625 // atomically release spin lock and block 620 626 BlockInternal( &this->lock ); 621 627 } 622 628 else { 623 unlock( &this->lock ); 624 } 625 } 626 627 void signal( signal_once * this ) { 629 unlock( &this->lock ); 630 } 631 } 632 633 void V(semaphore * this) { 634 thread_desc * thrd = NULL; 628 635 lock( &this->lock DEBUG_CTX2 ); 629 { 630 this->cond = true; 631 632 disable_interrupts(); 633 thread_desc * it; 634 while( it = pop_head( &this->blocked) ) { 635 ScheduleThread( it ); 636 } 637 enable_interrupts( DEBUG_CTX ); 638 } 636 this->count += 1; 637 if ( this->count <= 0 ) { 638 // remove task at head of waiting list 639 thrd = pop_head( &this->waiting ); 640 } 641 639 642 unlock( &this->lock ); 643 644 // make new owner 645 WakeThread( thrd ); 640 646 } 641 647
Note: See TracChangeset
for help on using the changeset viewer.