Ignore:
File:
1 edited

Legend:

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

    r43784ac r82f4063  
    1616
    1717#define __cforall_thread__
    18 #define _GNU_SOURCE
    1918
    2019#include "locks.hfa"
     
    2827forall(L & | is_blocking_lock(L)) {
    2928        struct info_thread {
    30                 // used to put info_thread on a dl queue (aka sequence)
    31                 inline Seqable;
     29                // used to put info_thread on a dl queue
     30                inline dlink(info_thread(L));
    3231
    3332                // waiting thread
     
    4342                bool signalled;
    4443        };
     44        P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) )
    4545
    4646        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) {
    47                 ((Seqable &) this){};
    4847                this.t = t;
    4948                this.info = info;
     
    5251
    5352        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         }
    6253}
    6354
     
    8677        // lock is held by some other thread
    8778        if ( owner != 0p && owner != thrd ) {
    88                 addTail( blocked_threads, *thrd );
     79                insert_last( blocked_threads, *thrd );
    8980                wait_count++;
    9081                unlock( lock );
     
    125116
    126117void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    127         $thread * t = &dropHead( blocked_threads );
     118        $thread * t = &try_pop_front( blocked_threads );
    128119        owner = t;
    129120        recursion_count = ( t ? 1 : 0 );
     
    154145        // lock held
    155146        if ( owner != 0p ) {
    156                 addTail( blocked_threads, *t );
     147                insert_last( blocked_threads, *t );
    157148                wait_count++;
    158149                unlock( lock );
     
    207198                //      may still be called after a thread has been removed from the queue but
    208199                //      before the alarm is unregistered
    209                 if ( listed(info_thd) ) {       // is thread on queue
     200                if ( (*info_thd)`isListed ) {   // is thread on queue
    210201                        info_thd->signalled = false;
    211202                        // remove this thread O(1)
    212                         remove( cond->blocked_threads, *info_thd );
     203                        remove( *info_thd );
    213204                        cond->count--;
    214205                        if( info_thd->lock ) {
     
    255246        bool notify_one( condition_variable(L) & this ) with( this ) {
    256247                lock( lock __cfaabi_dbg_ctx2 );
    257                 bool ret = !empty(blocked_threads);
    258                 process_popped(this, dropHead( blocked_threads ));
     248                bool ret = ! blocked_threads`isEmpty;
     249                process_popped(this, try_pop_front( blocked_threads ));
    259250                unlock( lock );
    260251                return ret;
     
    263254        bool notify_all( condition_variable(L) & this ) with(this) {
    264255                lock( lock __cfaabi_dbg_ctx2 );
    265                 bool ret = !empty(blocked_threads);
    266                 while( !empty(blocked_threads) ) {
    267                         process_popped(this, dropHead( blocked_threads ));
     256                bool ret = ! blocked_threads`isEmpty;
     257                while( ! blocked_threads`isEmpty ) {
     258                        process_popped(this, try_pop_front( blocked_threads ));
    268259                }
    269260                unlock( lock );
     
    272263
    273264        uintptr_t front( condition_variable(L) & this ) with(this) {
    274                 return empty(blocked_threads) ? NULL : head(blocked_threads).info;
     265                return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;
    275266        }
    276267
    277268        bool empty( condition_variable(L) & this ) with(this) {
    278269                lock( lock __cfaabi_dbg_ctx2 );
    279                 bool ret = empty(blocked_threads);
     270                bool ret = blocked_threads`isEmpty;
    280271                unlock( lock );
    281272                return ret;
     
    286277        size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    287278                // add info_thread to waiting queue
    288                 addTail( blocked_threads, *i );
     279                insert_last( blocked_threads, *i );
    289280                count++;
    290281                size_t recursion_count = 0;
Note: See TracChangeset for help on using the changeset viewer.