Changeset 82f4063


Ignore:
Timestamp:
May 26, 2021, 10:38:19 AM (16 months ago)
Author:
caparsons <caparson@…>
Branches:
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

Location:
libcfa/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/defs.hfa

    rc65b930 r82f4063  
    3131#ifdef __cforall
    3232#define __cfa_anonymous_object(x) inline struct x
     33#define __cfa_dlink(x) inline dlink(x)
    3334#else
    3435#define __cfa_anonymous_object(x) struct x __cfa_anonymous_object
     36#define __cfa_dlink(x) struct { struct x * next; struct x * back; } __dlink_substitute
    3537#endif
    3638
  • libcfa/src/bits/weakso_locks.hfa

    rc65b930 r82f4063  
    2121#include "bits/sequence.hfa"
    2222#include "bits/containers.hfa"
     23#include "containers/list.hfa"
    2324
    2425struct $thread;
     
    3132
    3233        // List of blocked threads
    33         Sequence( $thread ) blocked_threads;
     34        dlist( $thread ) blocked_threads;
    3435
    3536        // Count of current blocked threads
  • libcfa/src/concurrency/invoke.h

    rc65b930 r82f4063  
    2020
    2121#ifdef __cforall
     22#include "containers/list.hfa"
    2223extern "C" {
    2324#endif
     
    196197                } seqable;
    197198
     199                // used to put threads on dlist data structure
     200                __cfa_dlink($thread);
     201
    198202                struct {
    199203                        struct $thread * next;
     
    207211                #endif
    208212        };
     213        #ifdef __cforall
     214                P9_EMBEDDED( $thread, dlink($thread) )
     215        #endif
    209216        // Wrapper for gdb
    210217        struct cfathread_thread_t { struct $thread debug; };
     
    236243
    237244                static inline $thread *& Next( $thread * this ) __attribute__((const)) {
    238                         return this->seqable.next;
     245                                return this->seqable.next;
    239246                }
    240247
  • 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;
  • libcfa/src/concurrency/locks.hfa

    rc65b930 r82f4063  
    2121#include "bits/weakso_locks.hfa"
    2222#include "containers/queueLockFree.hfa"
     23#include "containers/list.hfa"
    2324
    2425#include "thread.hfa"
     
    4041
    4142static inline bool P(Semaphore0nary & this, $thread * thrd) {
    42         /* paranoid */ verify(!(thrd->seqable.next));
    43         /* paranoid */ verify(!(thrd`next));
     43        /* paranoid */ verify(!thrd`next);
     44        /* paranoid */ verify(!(&(*thrd)`next));
    4445
    4546        push(this.queue, thrd);
     
    250251
    251252//-----------------------------------------------------------------------------
    252 // info_thread
    253 // the info thread is a wrapper around a thread used
    254 // to store extra data for use in the condition variable
     253// // info_thread
     254// // the info thread is a wrapper around a thread used
     255// // to store extra data for use in the condition variable
    255256forall(L & | is_blocking_lock(L)) {
    256257        struct info_thread;
    257258
    258         // for use by sequence
    259         info_thread(L) *& Back( info_thread(L) * this );
    260         info_thread(L) *& Next( info_thread(L) * this );
     259        // // for use by sequence
     260        // info_thread(L) *& Back( info_thread(L) * this );
     261        // info_thread(L) *& Next( info_thread(L) * this );
    261262}
    262263
     
    269270
    270271                // List of blocked threads
    271                 Sequence( info_thread(L) ) blocked_threads;
     272                dlist( info_thread(L) ) blocked_threads;
    272273
    273274                // Count of current blocked threads
    274275                int count;
    275276        };
     277       
    276278
    277279        void  ?{}( condition_variable(L) & this );
Note: See TracChangeset for help on using the changeset viewer.