Ignore:
Timestamp:
May 26, 2021, 10:38:19 AM (3 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
bae0d35
Parents:
c65b930
Message:

switched unified locking to use dlist

File:
1 edited

Legend:

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

    rc65b930 r82f4063  
    2727forall(L & | is_blocking_lock(L)) {
    2828        struct info_thread {
    29                 // used to put info_thread on a dl queue (aka sequence)
    30                 inline Seqable;
     29                // used to put info_thread on a dl queue
     30                inline dlink(info_thread(L));
    3131
    3232                // waiting thread
     
    4242                bool signalled;
    4343        };
     44        P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) )
    4445
    4546        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) {
    46                 ((Seqable &) this){};
    4747                this.t = t;
    4848                this.info = info;
     
    5151
    5252        void ^?{}( info_thread(L) & this ) {}
    53 
    54         info_thread(L) *& Back( info_thread(L) * this ) {
    55                 return (info_thread(L) *)Back( (Seqable *)this );
    56         }
    57 
    58         info_thread(L) *& Next( info_thread(L) * this ) {
    59                 return (info_thread(L) *)Next( (Colable *)this );
    60         }
    6153}
    6254
     
    8577        // lock is held by some other thread
    8678        if ( owner != 0p && owner != thrd ) {
    87                 addTail( blocked_threads, *thrd );
     79                insert_last( blocked_threads, *thrd );
    8880                wait_count++;
    8981                unlock( lock );
     
    124116
    125117void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    126         $thread * t = &dropHead( blocked_threads );
     118        $thread * t = &try_pop_front( blocked_threads );
    127119        owner = t;
    128120        recursion_count = ( t ? 1 : 0 );
     
    153145        // lock held
    154146        if ( owner != 0p ) {
    155                 addTail( blocked_threads, *t );
     147                insert_last( blocked_threads, *t );
    156148                wait_count++;
    157149                unlock( lock );
     
    206198                //      may still be called after a thread has been removed from the queue but
    207199                //      before the alarm is unregistered
    208                 if ( listed(info_thd) ) {       // is thread on queue
     200                if ( (*info_thd)`isListed ) {   // is thread on queue
    209201                        info_thd->signalled = false;
    210202                        // remove this thread O(1)
    211                         remove( cond->blocked_threads, *info_thd );
     203                        remove( *info_thd );
    212204                        cond->count--;
    213205                        if( info_thd->lock ) {
     
    254246        bool notify_one( condition_variable(L) & this ) with( this ) {
    255247                lock( lock __cfaabi_dbg_ctx2 );
    256                 bool ret = !empty(blocked_threads);
    257                 process_popped(this, dropHead( blocked_threads ));
     248                bool ret = ! blocked_threads`isEmpty;
     249                process_popped(this, try_pop_front( blocked_threads ));
    258250                unlock( lock );
    259251                return ret;
     
    262254        bool notify_all( condition_variable(L) & this ) with(this) {
    263255                lock( lock __cfaabi_dbg_ctx2 );
    264                 bool ret = !empty(blocked_threads);
    265                 while( !empty(blocked_threads) ) {
    266                         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 ));
    267259                }
    268260                unlock( lock );
     
    271263
    272264        uintptr_t front( condition_variable(L) & this ) with(this) {
    273                 return empty(blocked_threads) ? NULL : head(blocked_threads).info;
     265                return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;
    274266        }
    275267
    276268        bool empty( condition_variable(L) & this ) with(this) {
    277269                lock( lock __cfaabi_dbg_ctx2 );
    278                 bool ret = empty(blocked_threads);
     270                bool ret = blocked_threads`isEmpty;
    279271                unlock( lock );
    280272                return ret;
     
    285277        size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    286278                // add info_thread to waiting queue
    287                 addTail( blocked_threads, *i );
     279                insert_last( blocked_threads, *i );
    288280                count++;
    289281                size_t recursion_count = 0;
Note: See TracChangeset for help on using the changeset viewer.