Ignore:
File:
1 edited

Legend:

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

    r454f478 rac5816d  
    77//-----------------------------------------------------------------------------
    88// info_thread
    9 forall(L & | is_blocking_lock(L)) {
     9forall(dtype L | is_blocking_lock(L)) {
    1010        struct info_thread {
    1111                // used to put info_thread on a dl queue (aka sequence)
     
    195195//-----------------------------------------------------------------------------
    196196// alarm node wrapper
    197 forall(L & | is_blocking_lock(L)) {
     197forall(dtype L | is_blocking_lock(L)) {
    198198        struct alarm_node_wrap {
    199199                alarm_node_t alarm_node;
     
    239239//-----------------------------------------------------------------------------
    240240// condition variable
    241 forall(L & | is_blocking_lock(L)) {
     241forall(dtype L | is_blocking_lock(L)) {
    242242
    243243        void ?{}( condition_variable(L) & this ){
     
    356356        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time         ) with(this) { WAIT_TIME( info, &l , time ) }
    357357}
    358 
    359 //-----------------------------------------------------------------------------
    360 // Semaphore
    361 void  ?{}( semaphore & this, int count = 1 ) {
    362         (this.lock){};
    363         this.count = count;
    364         (this.waiting){};
    365 }
    366 void ^?{}(semaphore & this) {}
    367 
    368 bool P(semaphore & this) with( this ){
    369         lock( lock __cfaabi_dbg_ctx2 );
    370         count -= 1;
    371         if ( count < 0 ) {
    372                 // queue current task
    373                 append( waiting, active_thread() );
    374 
    375                 // atomically release spin lock and block
    376                 unlock( lock );
    377                 park();
    378                 return true;
    379         }
    380         else {
    381             unlock( lock );
    382             return false;
    383         }
    384 }
    385 
    386 bool V(semaphore & this) with( this ) {
    387         $thread * thrd = 0p;
    388         lock( lock __cfaabi_dbg_ctx2 );
    389         count += 1;
    390         if ( count <= 0 ) {
    391                 // remove task at head of waiting list
    392                 thrd = pop_head( waiting );
    393         }
    394 
    395         unlock( lock );
    396 
    397         // make new owner
    398         unpark( thrd );
    399 
    400         return thrd != 0p;
    401 }
    402 
    403 bool V(semaphore & this, unsigned diff) with( this ) {
    404         $thread * thrd = 0p;
    405         lock( lock __cfaabi_dbg_ctx2 );
    406         int release = max(-count, (int)diff);
    407         count += diff;
    408         for(release) {
    409                 unpark( pop_head( waiting ) );
    410         }
    411 
    412         unlock( lock );
    413 
    414         return thrd != 0p;
    415 }
Note: See TracChangeset for help on using the changeset viewer.