Ignore:
File:
1 edited

Legend:

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

    r4e83bb7 rae06e0b  
    237237                // This pthread_cond_var member is called from the kernel, and therefore, cannot block, but it can spin.
    238238                lock( cond->lock __cfaabi_dbg_ctx2 );
     239
    239240                // this check is necessary to avoid a race condition since this timeout handler
    240241                //      may still be called after a thread has been removed from the queue but
     
    346347                size_t recursion_count = queue_and_get_recursion(this, &info);
    347348                alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info };
    348                 unlock( lock );
    349 
    350                 // registers alarm outside cond lock to avoid deadlock
    351349                register_self( &node_wrap.alarm_node );
     350                unlock( lock );
    352351
    353352                // blocks here
     
    438437                if ( ret ) {
    439438                        info_thread(L) & popped = try_pop_front( blocked_threads );
    440                         popped.signalled = true;
    441439                        on_notify(*popped.lock, popped.t);
    442440                }
     
    450448                while( ! blocked_threads`isEmpty ) {
    451449                        info_thread(L) & popped = try_pop_front( blocked_threads );
    452                         popped.signalled = true;
    453450                        on_notify(*popped.lock, popped.t);
    454451                }
     
    472469                size_t recursion_count = queue_and_get_recursion(this, &info);
    473470                pthread_alarm_node_wrap(L) node_wrap = { t, 0`s, callback, &this, &info };
    474                 unlock( lock );
    475 
    476                 // registers alarm outside cond lock to avoid deadlock
    477471                register_self( &node_wrap.alarm_node );
     472                unlock( lock );
    478473
    479474                // blocks here
     
    505500                return i.signalled;
    506501
    507         Duration getDuration(timespec t) {
    508                 timespec currTime;
    509                 clock_gettime(CLOCK_REALTIME, &currTime);
    510                 Duration waitUntil = { t };
    511                 Duration currDur = { currTime };
    512                 if ( currDur >= waitUntil ) return currDur - waitUntil;
    513                 Duration zero = { 0 };
    514                 return zero;
    515         }
    516 
    517502        bool wait( pthread_cond_var(L) & this, L & l, timespec t ) {
    518                 PTHREAD_WAIT_TIME( 0, &l , getDuration( t ) )
     503                Duration d = { t };
     504                WAIT_TIME( 0, &l , d )
    519505        }
    520506       
    521507        bool wait( pthread_cond_var(L) & this, L & l, uintptr_t info, timespec t  ) {
    522                 PTHREAD_WAIT_TIME( info, &l , getDuration( t ) )
     508                Duration d = { t };
     509                WAIT_TIME( info, &l , d )
    523510        }
    524511}
Note: See TracChangeset for help on using the changeset viewer.