Ignore:
File:
1 edited

Legend:

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

    re84ab3d r43784ac  
    2828forall(L & | is_blocking_lock(L)) {
    2929        struct info_thread {
    30                 // used to put info_thread on a dl queue
    31                 inline dlink(info_thread(L));
     30                // used to put info_thread on a dl queue (aka sequence)
     31                inline Seqable;
    3232
    3333                // waiting thread
    34                 struct thread$ * t;
     34                struct $thread * t;
    3535
    3636                // shadow field
     
    4343                bool signalled;
    4444        };
    45         P9_EMBEDDED( info_thread(L), dlink(info_thread(L)) )
    46 
    47         void ?{}( info_thread(L) & this, thread$ * t, uintptr_t info, L * l ) {
     45
     46        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info, L * l ) {
     47                ((Seqable &) this){};
    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        }
    5462}
    5563
     
    7179void lock( blocking_lock & this ) with( this ) {
    7280        lock( lock __cfaabi_dbg_ctx2 );
    73         thread$ * thrd = active_thread();
     81        $thread * thrd = active_thread();
    7482
    7583        // single acquisition lock is held by current thread
     
    7886        // lock is held by some other thread
    7987        if ( owner != 0p && owner != thrd ) {
    80                 insert_last( blocked_threads, *thrd );
     88                addTail( blocked_threads, *thrd );
    8189                wait_count++;
    8290                unlock( lock );
     
    117125
    118126void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    119         thread$ * t = &try_pop_front( blocked_threads );
     127        $thread * t = &dropHead( blocked_threads );
    120128        owner = t;
    121129        recursion_count = ( t ? 1 : 0 );
     
    142150}
    143151
    144 void on_notify( blocking_lock & this, thread$ * t ) with( this ) {
     152void on_notify( blocking_lock & this, $thread * t ) with( this ) {
    145153        lock( lock __cfaabi_dbg_ctx2 );
    146154        // lock held
    147155        if ( owner != 0p ) {
    148                 insert_last( blocked_threads, *t );
     156                addTail( blocked_threads, *t );
    149157                wait_count++;
    150158                unlock( lock );
     
    199207                //      may still be called after a thread has been removed from the queue but
    200208                //      before the alarm is unregistered
    201                 if ( (*info_thd)`isListed ) {   // is thread on queue
     209                if ( listed(info_thd) ) {       // is thread on queue
    202210                        info_thd->signalled = false;
    203211                        // remove this thread O(1)
    204                         remove( *info_thd );
     212                        remove( cond->blocked_threads, *info_thd );
    205213                        cond->count--;
    206214                        if( info_thd->lock ) {
     
    247255        bool notify_one( condition_variable(L) & this ) with( this ) {
    248256                lock( lock __cfaabi_dbg_ctx2 );
    249                 bool ret = ! blocked_threads`isEmpty;
    250                 process_popped(this, try_pop_front( blocked_threads ));
     257                bool ret = !empty(blocked_threads);
     258                process_popped(this, dropHead( blocked_threads ));
    251259                unlock( lock );
    252260                return ret;
     
    255263        bool notify_all( condition_variable(L) & this ) with(this) {
    256264                lock( lock __cfaabi_dbg_ctx2 );
    257                 bool ret = ! blocked_threads`isEmpty;
    258                 while( ! blocked_threads`isEmpty ) {
    259                         process_popped(this, try_pop_front( blocked_threads ));
     265                bool ret = !empty(blocked_threads);
     266                while( !empty(blocked_threads) ) {
     267                        process_popped(this, dropHead( blocked_threads ));
    260268                }
    261269                unlock( lock );
     
    264272
    265273        uintptr_t front( condition_variable(L) & this ) with(this) {
    266                 return blocked_threads`isEmpty ? NULL : blocked_threads`first.info;
     274                return empty(blocked_threads) ? NULL : head(blocked_threads).info;
    267275        }
    268276
    269277        bool empty( condition_variable(L) & this ) with(this) {
    270278                lock( lock __cfaabi_dbg_ctx2 );
    271                 bool ret = blocked_threads`isEmpty;
     279                bool ret = empty(blocked_threads);
    272280                unlock( lock );
    273281                return ret;
     
    278286        size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    279287                // add info_thread to waiting queue
    280                 insert_last( blocked_threads, *i );
     288                addTail( blocked_threads, *i );
    281289                count++;
    282290                size_t recursion_count = 0;
     
    366374}
    367375
    368 thread$ * V (semaphore & this, const bool doUnpark ) with( this ) {
    369         thread$ * thrd = 0p;
     376$thread * V (semaphore & this, const bool doUnpark ) with( this ) {
     377        $thread * thrd = 0p;
    370378        lock( lock __cfaabi_dbg_ctx2 );
    371379        count += 1;
     
    384392
    385393bool V(semaphore & this) with( this ) {
    386         thread$ * thrd = V(this, true);
     394        $thread * thrd = V(this, true);
    387395        return thrd != 0p;
    388396}
    389397
    390398bool V(semaphore & this, unsigned diff) with( this ) {
    391         thread$ * thrd = 0p;
     399        $thread * thrd = 0p;
    392400        lock( lock __cfaabi_dbg_ctx2 );
    393401        int release = max(-count, (int)diff);
Note: See TracChangeset for help on using the changeset viewer.