Ignore:
File:
1 edited

Legend:

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

    r43784ac re84ab3d  
    2828forall(L & | is_blocking_lock(L)) {
    2929        struct info_thread {
    30                 // used to put info_thread on a dl queue (aka sequence)
    31                 inline Seqable;
     30                // used to put info_thread on a dl queue
     31                inline dlink(info_thread(L));
    3232
    3333                // waiting thread
    34                 struct $thread * t;
     34                struct thread$ * t;
    3535
    3636                // shadow field
     
    4343                bool signalled;
    4444        };
    45 
    46         void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) {
    47                 ((Seqable &) this){};
     45        P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) )
     46
     47        void ?{}( info_thread(L) & this, thread$ * t, uintptr_t info, L * l ) {
    4848                this.t = t;
    4949                this.info = info;
     
    5252
    5353        void ^?{}( info_thread(L) & this ) {}
    54 
    55         info_thread(L) *& Back( info_thread(L) * this ) {
    56                 return (info_thread(L) *)Back( (Seqable *)this );
    57         }
    58 
    59         info_thread(L) *& Next( info_thread(L) * this ) {
    60                 return (info_thread(L) *)Next( (Colable *)this );
    61         }
    6254}
    6355
     
    7971void lock( blocking_lock & this ) with( this ) {
    8072        lock( lock __cfaabi_dbg_ctx2 );
    81         $thread * thrd = active_thread();
     73        thread$ * thrd = active_thread();
    8274
    8375        // single acquisition lock is held by current thread
     
    8678        // lock is held by some other thread
    8779        if ( owner != 0p && owner != thrd ) {
    88                 addTail( blocked_threads, *thrd );
     80                insert_last( blocked_threads, *thrd );
    8981                wait_count++;
    9082                unlock( lock );
     
    125117
    126118void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    127         $thread * t = &dropHead( blocked_threads );
     119        thread$ * t = &try_pop_front( blocked_threads );
    128120        owner = t;
    129121        recursion_count = ( t ? 1 : 0 );
     
    150142}
    151143
    152 void on_notify( blocking_lock & this, $thread * t ) with( this ) {
     144void on_notify( blocking_lock & this, thread$ * t ) with( this ) {
    153145        lock( lock __cfaabi_dbg_ctx2 );
    154146        // lock held
    155147        if ( owner != 0p ) {
    156                 addTail( blocked_threads, *t );
     148                insert_last( blocked_threads, *t );
    157149                wait_count++;
    158150                unlock( lock );
     
    207199                //      may still be called after a thread has been removed from the queue but
    208200                //      before the alarm is unregistered
    209                 if ( listed(info_thd) ) {       // is thread on queue
     201                if ( (*info_thd)`isListed ) {   // is thread on queue
    210202                        info_thd->signalled = false;
    211203                        // remove this thread O(1)
    212                         remove( cond->blocked_threads, *info_thd );
     204                        remove( *info_thd );
    213205                        cond->count--;
    214206                        if( info_thd->lock ) {
     
    255247        bool notify_one( condition_variable(L) & this ) with( this ) {
    256248                lock( lock __cfaabi_dbg_ctx2 );
    257                 bool ret = !empty(blocked_threads);
    258                 process_popped(this, dropHead( blocked_threads ));
     249                bool ret = ! blocked_threads`isEmpty;
     250                process_popped(this, try_pop_front( blocked_threads ));
    259251                unlock( lock );
    260252                return ret;
     
    263255        bool notify_all( condition_variable(L) & this ) with(this) {
    264256                lock( lock __cfaabi_dbg_ctx2 );
    265                 bool ret = !empty(blocked_threads);
    266                 while( !empty(blocked_threads) ) {
    267                         process_popped(this, dropHead( blocked_threads ));
     257                bool ret = ! blocked_threads`isEmpty;
     258                while( ! blocked_threads`isEmpty ) {
     259                        process_popped(this, try_pop_front( blocked_threads ));
    268260                }
    269261                unlock( lock );
     
    272264
    273265        uintptr_t front( condition_variable(L) & this ) with(this) {
    274                 return empty(blocked_threads) ? NULL : head(blocked_threads).info;
     266                return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;
    275267        }
    276268
    277269        bool empty( condition_variable(L) & this ) with(this) {
    278270                lock( lock __cfaabi_dbg_ctx2 );
    279                 bool ret = empty(blocked_threads);
     271                bool ret = blocked_threads`isEmpty;
    280272                unlock( lock );
    281273                return ret;
     
    286278        size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    287279                // add info_thread to waiting queue
    288                 addTail( blocked_threads, *i );
     280                insert_last( blocked_threads, *i );
    289281                count++;
    290282                size_t recursion_count = 0;
     
    374366}
    375367
    376 $thread * V (semaphore & this, const bool doUnpark ) with( this ) {
    377         $thread * thrd = 0p;
     368thread$ * V (semaphore & this, const bool doUnpark ) with( this ) {
     369        thread$ * thrd = 0p;
    378370        lock( lock __cfaabi_dbg_ctx2 );
    379371        count += 1;
     
    392384
    393385bool V(semaphore & this) with( this ) {
    394         $thread * thrd = V(this, true);
     386        thread$ * thrd = V(this, true);
    395387        return thrd != 0p;
    396388}
    397389
    398390bool V(semaphore & this, unsigned diff) with( this ) {
    399         $thread * thrd = 0p;
     391        thread$ * thrd = 0p;
    400392        lock( lock __cfaabi_dbg_ctx2 );
    401393        int release = max(-count, (int)diff);
Note: See TracChangeset for help on using the changeset viewer.