Changes in src/libcfa/concurrency/kernel.c [ea7d2b0:6a5be52]
- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
rea7d2b0 r6a5be52 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); … … 242 242 void finishRunning(processor * this) { 243 243 if( this->finish.action_code == Release ) { 244 unlock( *this->finish.lock );244 unlock( this->finish.lock ); 245 245 } 246 246 else if( this->finish.action_code == Schedule ) { … … 248 248 } 249 249 else if( this->finish.action_code == Release_Schedule ) { 250 unlock( *this->finish.lock );250 unlock( this->finish.lock ); 251 251 ScheduleThread( this->finish.thrd ); 252 252 } 253 253 else if( this->finish.action_code == Release_Multi ) { 254 254 for(int i = 0; i < this->finish.lock_count; i++) { 255 unlock( *this->finish.locks[i] );255 unlock( this->finish.locks[i] ); 256 256 } 257 257 } 258 258 else if( this->finish.action_code == Release_Multi_Schedule ) { 259 259 for(int i = 0; i < this->finish.lock_count; i++) { 260 unlock( *this->finish.locks[i] );260 unlock( this->finish.locks[i] ); 261 261 } 262 262 for(int i = 0; i < this->finish.thrd_count; i++) { … … 334 334 verifyf( thrd->next == NULL, "Expected null got %p", thrd->next ); 335 335 336 lock( this_processor->cltr->ready_queue_lock DEBUG_CTX2 );337 append( this_processor->cltr->ready_queue, thrd );338 unlock( this_processor->cltr->ready_queue_lock );336 lock( &this_processor->cltr->ready_queue_lock DEBUG_CTX2 ); 337 append( &this_processor->cltr->ready_queue, thrd ); 338 unlock( &this_processor->cltr->ready_queue_lock ); 339 339 340 340 verify( disable_preempt_count > 0 ); … … 343 343 thread_desc * nextThread(cluster * this) { 344 344 verify( disable_preempt_count > 0 ); 345 lock( this->ready_queue_lock DEBUG_CTX2 );346 thread_desc * head = pop_head( this->ready_queue );347 unlock( this->ready_queue_lock );345 lock( &this->ready_queue_lock DEBUG_CTX2 ); 346 thread_desc * head = pop_head( &this->ready_queue ); 347 unlock( &this->ready_queue_lock ); 348 348 verify( disable_preempt_count > 0 ); 349 349 return head; … … 358 358 } 359 359 360 void BlockInternal( __spinlock_t* lock ) {360 void BlockInternal( spinlock * lock ) { 361 361 disable_interrupts(); 362 362 this_processor->finish.action_code = Release; … … 384 384 } 385 385 386 void BlockInternal( __spinlock_t* lock, thread_desc * thrd ) {386 void BlockInternal( spinlock * lock, thread_desc * thrd ) { 387 387 assert(thrd); 388 388 disable_interrupts(); … … 398 398 } 399 399 400 void BlockInternal( __spinlock_t * 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_t * 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; … … 426 426 } 427 427 428 void LeaveThread( __spinlock_t* lock, thread_desc * thrd) {428 void LeaveThread(spinlock * lock, thread_desc * thrd) { 429 429 verify( disable_preempt_count > 0 ); 430 430 this_processor->finish.action_code = thrd ? Release_Schedule : Release; … … 516 516 } 517 517 518 static __spinlock_tkernel_abort_lock;519 static __spinlock_tkernel_debug_lock;518 static spinlock kernel_abort_lock; 519 static spinlock kernel_debug_lock; 520 520 static bool kernel_abort_called = false; 521 521 … … 523 523 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 524 524 // the globalAbort flag is true. 525 lock( kernel_abort_lock DEBUG_CTX2 );525 lock( &kernel_abort_lock DEBUG_CTX2 ); 526 526 527 527 // first task to abort ? 528 528 if ( !kernel_abort_called ) { // not first task to abort ? 529 529 kernel_abort_called = true; 530 unlock( kernel_abort_lock );530 unlock( &kernel_abort_lock ); 531 531 } 532 532 else { 533 unlock( kernel_abort_lock );533 unlock( &kernel_abort_lock ); 534 534 535 535 sigset_t mask; … … 561 561 extern "C" { 562 562 void __lib_debug_acquire() { 563 lock( kernel_debug_lock DEBUG_CTX2 );563 lock( &kernel_debug_lock DEBUG_CTX2 ); 564 564 } 565 565 566 566 void __lib_debug_release() { 567 unlock( kernel_debug_lock );567 unlock( &kernel_debug_lock ); 568 568 } 569 569 } … … 574 574 //----------------------------------------------------------------------------- 575 575 // Locks 576 void ?{}( spinlock & this ) { 577 this.lock = 0; 578 } 579 void ^?{}( spinlock & this ) { 580 581 } 582 583 bool try_lock( spinlock * this DEBUG_CTX_PARAM2 ) { 584 return this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0; 585 } 586 587 void lock( spinlock * this DEBUG_CTX_PARAM2 ) { 588 for ( unsigned int i = 1;; i += 1 ) { 589 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; } 590 } 591 LIB_DEBUG_DO( 592 this->prev_name = caller; 593 this->prev_thrd = this_thread; 594 ) 595 } 596 597 void lock_yield( spinlock * this DEBUG_CTX_PARAM2 ) { 598 for ( unsigned int i = 1;; i += 1 ) { 599 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; } 600 yield(); 601 } 602 LIB_DEBUG_DO( 603 this->prev_name = caller; 604 this->prev_thrd = this_thread; 605 ) 606 } 607 608 609 void unlock( spinlock * this ) { 610 __sync_lock_release_4( &this->lock ); 611 } 612 576 613 void ?{}( semaphore & this, int count = 1 ) { 577 614 (this.lock){}; … … 581 618 void ^?{}(semaphore & this) {} 582 619 583 void P(semaphore &this) {584 lock( this.lock DEBUG_CTX2 );585 this .count -= 1;586 if ( this .count < 0 ) {620 void P(semaphore * this) { 621 lock( &this->lock DEBUG_CTX2 ); 622 this->count -= 1; 623 if ( this->count < 0 ) { 587 624 // queue current task 588 append( this.waiting, (thread_desc *)this_thread );625 append( &this->waiting, (thread_desc *)this_thread ); 589 626 590 627 // atomically release spin lock and block 591 BlockInternal( &this .lock );628 BlockInternal( &this->lock ); 592 629 } 593 630 else { 594 unlock( this.lock );595 } 596 } 597 598 void V(semaphore &this) {631 unlock( &this->lock ); 632 } 633 } 634 635 void V(semaphore * this) { 599 636 thread_desc * thrd = NULL; 600 lock( this.lock DEBUG_CTX2 );601 this .count += 1;602 if ( this .count <= 0 ) {637 lock( &this->lock DEBUG_CTX2 ); 638 this->count += 1; 639 if ( this->count <= 0 ) { 603 640 // remove task at head of waiting list 604 thrd = pop_head( this.waiting );605 } 606 607 unlock( this.lock );641 thrd = pop_head( &this->waiting ); 642 } 643 644 unlock( &this->lock ); 608 645 609 646 // make new owner … … 618 655 } 619 656 620 void append( __thread_queue_t &this, thread_desc * t ) {621 verify(this .tail != NULL);622 *this .tail = t;623 this .tail = &t->next;624 } 625 626 thread_desc * pop_head( __thread_queue_t &this ) {627 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; 628 665 if( head ) { 629 this .head = head->next;666 this->head = head->next; 630 667 if( !head->next ) { 631 this .tail = &this.head;668 this->tail = &this->head; 632 669 } 633 670 head->next = NULL; … … 636 673 } 637 674 638 thread_desc * remove( __thread_queue_t &this, thread_desc ** it ) {675 thread_desc * remove( __thread_queue_t * this, thread_desc ** it ) { 639 676 thread_desc * thrd = *it; 640 677 verify( thrd ); … … 642 679 (*it) = thrd->next; 643 680 644 if( this .tail == &thrd->next ) {645 this .tail = it;681 if( this->tail == &thrd->next ) { 682 this->tail = it; 646 683 } 647 684 648 685 thrd->next = NULL; 649 686 650 verify( (this .head == NULL) == (&this.head == this.tail) );651 verify( *this .tail == NULL );687 verify( (this->head == NULL) == (&this->head == this->tail) ); 688 verify( *this->tail == NULL ); 652 689 return thrd; 653 690 } … … 657 694 } 658 695 659 void push( __condition_stack_t &this, __condition_criterion_t * t ) {696 void push( __condition_stack_t * this, __condition_criterion_t * t ) { 660 697 verify( !t->next ); 661 t->next = this .top;662 this .top = t;663 } 664 665 __condition_criterion_t * pop( __condition_stack_t &this ) {666 __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; 667 704 if( top ) { 668 this .top = top->next;705 this->top = top->next; 669 706 top->next = NULL; 670 707 }
Note:
See TracChangeset
for help on using the changeset viewer.