Ignore:
Timestamp:
Jan 20, 2021, 5:35:39 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Re-arranged and commented low-level headers.
Main goal was for better support of weakso locks that are comming.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    rdafbde8 r454f478  
    224224        }
    225225
    226         V( this->terminated );
     226        post( this->terminated );
    227227
    228228        if(this == mainProcessor) {
     
    665665//=============================================================================================
    666666//-----------------------------------------------------------------------------
    667 // Locks
    668 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 task
    680                 append( waiting, active_thread() );
    681 
    682                 // atomically release spin lock and block
    683                 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 list
    699                 thrd = pop_head( waiting );
    700         }
    701 
    702         unlock( lock );
    703 
    704         // make new owner
    705         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 //-----------------------------------------------------------------------------
    725667// Debug
    726668__cfaabi_dbg_debug_do(
Note: See TracChangeset for help on using the changeset viewer.