Changeset 454f478 for libcfa/src/concurrency/kernel.cfa
- Timestamp:
- Jan 20, 2021, 5:35:39 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 9db2c92
- Parents:
- dafbde8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.cfa
rdafbde8 r454f478 224 224 } 225 225 226 V( this->terminated );226 post( this->terminated ); 227 227 228 228 if(this == mainProcessor) { … … 665 665 //============================================================================================= 666 666 //----------------------------------------------------------------------------- 667 // Locks668 void ?{}( semaphore & this, int count = 1 ) {669 (this.lock){};670 this.count = count;671 (this.waiting){};672 }673 void ^?{}(semaphore & this) {}674 675 bool P(semaphore & this) with( this ){676 lock( lock __cfaabi_dbg_ctx2 );677 count -= 1;678 if ( count < 0 ) {679 // queue current task680 append( waiting, active_thread() );681 682 // atomically release spin lock and block683 unlock( lock );684 park();685 return true;686 }687 else {688 unlock( lock );689 return false;690 }691 }692 693 bool V(semaphore & this) with( this ) {694 $thread * thrd = 0p;695 lock( lock __cfaabi_dbg_ctx2 );696 count += 1;697 if ( count <= 0 ) {698 // remove task at head of waiting list699 thrd = pop_head( waiting );700 }701 702 unlock( lock );703 704 // make new owner705 unpark( thrd );706 707 return thrd != 0p;708 }709 710 bool V(semaphore & this, unsigned diff) with( this ) {711 $thread * thrd = 0p;712 lock( lock __cfaabi_dbg_ctx2 );713 int release = max(-count, (int)diff);714 count += diff;715 for(release) {716 unpark( pop_head( waiting ) );717 }718 719 unlock( lock );720 721 return thrd != 0p;722 }723 724 //-----------------------------------------------------------------------------725 667 // Debug 726 668 __cfaabi_dbg_debug_do(
Note: See TracChangeset
for help on using the changeset viewer.