Changeset 3f7e12cb for src/libcfa/concurrency/kernel.c
- Timestamp:
- Nov 8, 2017, 5:43:33 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:
- 954908d
- Parents:
- 78315272 (diff), e35f30a (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/kernel.c
r78315272 r3f7e12cb 106 106 107 107 void ?{}( thread_desc & this, current_stack_info_t * info) { 108 (this. cor){ info };108 (this.self_cor){ info }; 109 109 } 110 110 … … 158 158 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", &this); 159 159 this.do_terminate = true; 160 P( &this.terminated );160 P( this.terminated ); 161 161 pthread_join( this.kernel_thread, NULL ); 162 162 } … … 216 216 } 217 217 218 V( &this->terminated );218 V( this->terminated ); 219 219 220 220 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this); … … 328 328 // if( !thrd ) return; 329 329 verify( thrd ); 330 verify( thrd-> cor.state != Halted );330 verify( thrd->self_cor.state != Halted ); 331 331 332 332 verify( disable_preempt_count > 0 ); … … 335 335 336 336 lock( &this_processor->cltr->ready_queue_lock DEBUG_CTX2 ); 337 append( &this_processor->cltr->ready_queue, thrd );337 append( this_processor->cltr->ready_queue, thrd ); 338 338 unlock( &this_processor->cltr->ready_queue_lock ); 339 339 … … 344 344 verify( disable_preempt_count > 0 ); 345 345 lock( &this->ready_queue_lock DEBUG_CTX2 ); 346 thread_desc * head = pop_head( &this->ready_queue );346 thread_desc * head = pop_head( this->ready_queue ); 347 347 unlock( &this->ready_queue_lock ); 348 348 verify( disable_preempt_count > 0 ); … … 373 373 assert(thrd); 374 374 disable_interrupts(); 375 assert( thrd-> cor.state != Halted );375 assert( thrd->self_cor.state != Halted ); 376 376 this_processor->finish.action_code = Schedule; 377 377 this_processor->finish.thrd = thrd; … … 398 398 } 399 399 400 void BlockInternal(spinlock * * locks, unsigned short count) {400 void BlockInternal(spinlock * locks [], unsigned short count) { 401 401 disable_interrupts(); 402 402 this_processor->finish.action_code = Release_Multi; … … 411 411 } 412 412 413 void BlockInternal(spinlock * * locks, unsigned short lock_count, thread_desc ** thrds, unsigned short thrd_count) {413 void BlockInternal(spinlock * locks [], unsigned short lock_count, thread_desc * thrds [], unsigned short thrd_count) { 414 414 disable_interrupts(); 415 415 this_processor->finish.action_code = Release_Multi_Schedule; … … 466 466 this_processor = mainProcessor; 467 467 this_thread = mainThread; 468 this_coroutine = &mainThread-> cor;468 this_coroutine = &mainThread->self_cor; 469 469 470 470 // Enable preemption … … 547 547 thread_desc * thrd = kernel_data; 548 548 549 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd-> cor.name, thrd );550 __lib_debug_write( STDERR_FILENO,abort_text, len );549 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd ); 550 __lib_debug_write( abort_text, len ); 551 551 552 552 if ( thrd != this_coroutine ) { 553 553 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine->name, this_coroutine ); 554 __lib_debug_write( STDERR_FILENO,abort_text, len );554 __lib_debug_write( abort_text, len ); 555 555 } 556 556 else { 557 __lib_debug_write( STDERR_FILENO,".\n", 2 );557 __lib_debug_write( ".\n", 2 ); 558 558 } 559 559 } … … 618 618 void ^?{}(semaphore & this) {} 619 619 620 void P(semaphore *this) {621 lock( &this ->lock DEBUG_CTX2 );622 this ->count -= 1;623 if ( this ->count < 0 ) {620 void P(semaphore & this) { 621 lock( &this.lock DEBUG_CTX2 ); 622 this.count -= 1; 623 if ( this.count < 0 ) { 624 624 // queue current task 625 append( &this->waiting, (thread_desc *)this_thread );625 append( this.waiting, (thread_desc *)this_thread ); 626 626 627 627 // atomically release spin lock and block 628 BlockInternal( &this ->lock );628 BlockInternal( &this.lock ); 629 629 } 630 630 else { 631 unlock( &this ->lock );632 } 633 } 634 635 void V(semaphore *this) {631 unlock( &this.lock ); 632 } 633 } 634 635 void V(semaphore & this) { 636 636 thread_desc * thrd = NULL; 637 lock( &this ->lock DEBUG_CTX2 );638 this ->count += 1;639 if ( this ->count <= 0 ) {637 lock( &this.lock DEBUG_CTX2 ); 638 this.count += 1; 639 if ( this.count <= 0 ) { 640 640 // remove task at head of waiting list 641 thrd = pop_head( &this->waiting );642 } 643 644 unlock( &this ->lock );641 thrd = pop_head( this.waiting ); 642 } 643 644 unlock( &this.lock ); 645 645 646 646 // make new owner … … 655 655 } 656 656 657 void append( __thread_queue_t *this, thread_desc * t ) {658 verify(this ->tail != NULL);659 *this ->tail = t;660 this ->tail = &t->next;661 } 662 663 thread_desc * pop_head( __thread_queue_t *this ) {664 thread_desc * head = this ->head;657 void append( __thread_queue_t & this, thread_desc * t ) { 658 verify(this.tail != NULL); 659 *this.tail = t; 660 this.tail = &t->next; 661 } 662 663 thread_desc * pop_head( __thread_queue_t & this ) { 664 thread_desc * head = this.head; 665 665 if( head ) { 666 this ->head = head->next;666 this.head = head->next; 667 667 if( !head->next ) { 668 this ->tail = &this->head;668 this.tail = &this.head; 669 669 } 670 670 head->next = NULL; … … 673 673 } 674 674 675 thread_desc * remove( __thread_queue_t *this, thread_desc ** it ) {675 thread_desc * remove( __thread_queue_t & this, thread_desc ** it ) { 676 676 thread_desc * thrd = *it; 677 677 verify( thrd ); … … 679 679 (*it) = thrd->next; 680 680 681 if( this ->tail == &thrd->next ) {682 this ->tail = it;681 if( this.tail == &thrd->next ) { 682 this.tail = it; 683 683 } 684 684 685 685 thrd->next = NULL; 686 686 687 verify( (this ->head == NULL) == (&this->head == this->tail) );688 verify( *this ->tail == NULL );687 verify( (this.head == NULL) == (&this.head == this.tail) ); 688 verify( *this.tail == NULL ); 689 689 return thrd; 690 690 } … … 694 694 } 695 695 696 void push( __condition_stack_t *this, __condition_criterion_t * t ) {696 void push( __condition_stack_t & this, __condition_criterion_t * t ) { 697 697 verify( !t->next ); 698 t->next = this ->top;699 this ->top = t;700 } 701 702 __condition_criterion_t * pop( __condition_stack_t *this ) {703 __condition_criterion_t * top = this ->top;698 t->next = this.top; 699 this.top = t; 700 } 701 702 __condition_criterion_t * pop( __condition_stack_t & this ) { 703 __condition_criterion_t * top = this.top; 704 704 if( top ) { 705 this ->top = top->next;705 this.top = top->next; 706 706 top->next = NULL; 707 707 }
Note:
See TracChangeset
for help on using the changeset viewer.