Ignore:
File:
1 edited

Legend:

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

    r7f958c4 r708ae38  
    220220
    221221//-----------------------------------------------------------------------------
    222 // Synchronization Locks
     222// condition variable
    223223forall(L & | is_blocking_lock(L)) {
    224224
    225         //-----------------------------------------------------------------------------
    226         // condition variable
    227225        void ?{}( condition_variable(L) & this ){
    228226                this.lock{};
     
    339337        bool wait( condition_variable(L) & this, L & l, Duration duration                 ) with(this) { WAIT_TIME( 0   , &l , duration ) }
    340338        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { WAIT_TIME( info, &l , duration ) }
    341 
    342         //-----------------------------------------------------------------------------
    343         // fast_cond_var
    344         void  ?{}( fast_cond_var(L) & this ){
    345                 this.blocked_threads{};
    346                 #ifdef __CFA_DEBUG__
    347                 this.lock_used = 0p;
    348                 #endif
    349         }
    350         void ^?{}( fast_cond_var(L) & this ){ }
    351 
    352         bool notify_one( fast_cond_var(L) & this ) with(this) {
    353                 bool ret = ! blocked_threads`isEmpty;
    354                 if ( ret ) {
    355                         info_thread(L) & popped = try_pop_front( blocked_threads );
    356                         on_notify(*popped.lock, popped.t);
    357                 }
    358                 return ret;
    359         }
    360         bool notify_all( fast_cond_var(L) & this ) with(this) {
    361                 bool ret = ! blocked_threads`isEmpty;
    362                 while( ! blocked_threads`isEmpty ) {
    363                         info_thread(L) & popped = try_pop_front( blocked_threads );
    364                         on_notify(*popped.lock, popped.t);
    365                 }
    366                 return ret;
    367         }
    368 
    369         uintptr_t front( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; }
    370         bool empty ( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; }
    371 
    372         void wait( fast_cond_var(L) & this, L & l ) {
    373                 wait( this, l, 0 );
    374         }
    375 
    376         void wait( fast_cond_var(L) & this, L & l, uintptr_t info ) with(this) {
    377                 // brand cond lock with lock
    378                 #ifdef __CFA_DEBUG__
    379                         if ( lock_used == 0p ) lock_used = &l;
    380                         else { assert(lock_used == &l); }
    381                 #endif
    382                 info_thread( L ) i = { active_thread(), info, &l };
    383                 insert_last( blocked_threads, i );
    384                 size_t recursion_count = on_wait( *i.lock );
    385                 park( );
    386                 on_wakeup(*i.lock, recursion_count);
    387         }
    388339}
    389340
Note: See TracChangeset for help on using the changeset viewer.