Changeset a6b48f6


Ignore:
Timestamp:
Dec 24, 2024, 10:52:13 AM (2 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
2853d6f, 5db580e
Parents:
4f4ae60
Message:

formatting, comment out unused parameter names to remove warnings

Location:
libcfa/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified libcfa/src/collections/lockfree.hfa

    r4f4ae60 ra6b48f6  
    66#include <bits/defs.hfa>
    77
    8 forall( T &) {
     8forall( T & ) {
    99        //------------------------------------------------------------
    1010        // Queue based on the MCS lock
     
    200200forall( T & )
    201201struct LinkData {
    202         T * volatile top;                                                               // pointer to stack top
    203         uintptr_t count;                                                                // count each push
     202        T * volatile top;                                                                       // pointer to stack top
     203        uintptr_t count;                                                                        // count each push
    204204};
    205205
     
    215215}; // Link
    216216
    217 forall( T | sized(T) | { Link(T) * ?`next( T * ); } ) {
     217forall( T /*| sized(T)*/ | { Link(T) * ?`next( T * ); } ) {
    218218        struct StackLF {
    219219                Link(T) stack;
     
    235235                        Link(T) t @= stack;                                                     // atomic assignment unnecessary, or use CAA
    236236                        for () {                                                                        // busy wait
    237                                 if ( t.data.top == 0p ) return 0p;                              // empty stack ?
     237                                if ( t.data.top == 0p ) return 0p;              // empty stack ?
    238238                                Link(T) * next = ( t.data.top )`next;
    239239                                if ( __atomic_compare_exchange_n( &stack.atom, &t.atom, (Link(T))@{ (LinkData(T))@{ next->data.top, t.data.count } }.atom, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return t.data.top; // attempt to update top node
  • TabularUnified libcfa/src/concurrency/locks.hfa

    r4f4ae60 ra6b48f6  
    1010// Author           : Colby Alexander Parsons
    1111// Created On       : Thu Jan 21 19:46:50 2021
    12 // Last Modified By :
    13 // Last Modified On :
    14 // Update Count     :
     12// Last Modified By : Peter A. Buhr
     13// Last Modified On : Tue Dec 24 09:36:52 2024
     14// Update Count     : 16
    1515//
    1616
     
    3333
    3434// futex headers
    35 #include <linux/futex.h>      /* Definition of FUTEX_* constants */
    36 #include <sys/syscall.h>      /* Definition of SYS_* constants */
    37 #include <unistd.h>           /* Definition of syscall routine */
     35#include <linux/futex.h>                                                                // Definition of FUTEX_* constants
     36#include <sys/syscall.h>                                                                // Definition of SYS_* constants
     37#include <unistd.h>                                                                             // Definition of syscall routine
    3838
    3939typedef void (*__cfa_pre_park)( void * );
     
    4343//-----------------------------------------------------------------------------
    4444// is_blocking_lock
    45 forall( L & | sized(L) )
     45forall( L & /*| sized( L )*/ )
    4646trait is_blocking_lock {
    4747        // For synchronization locks to use when acquiring
     
    6363
    6464#define DEFAULT_ON_NOTIFY( lock_type ) \
    65     static inline void on_notify( lock_type & this, thread$ * t ){ unpark(t); }
     65    static inline void on_notify( lock_type & /*this*/, thread$ * t ){ unpark( t ); }
    6666
    6767#define DEFAULT_ON_WAIT( lock_type ) \
     
    7474// on_wakeup impl if lock should be reacquired after waking up
    7575#define DEFAULT_ON_WAKEUP_REACQ( lock_type ) \
    76     static inline void on_wakeup( lock_type & this, size_t recursion ) { lock( this ); }
     76    static inline void on_wakeup( lock_type & this, size_t /*recursion*/ ) { lock( this ); }
    7777
    7878// on_wakeup impl if lock will not be reacquired after waking up
    7979#define DEFAULT_ON_WAKEUP_NO_REACQ( lock_type ) \
    80     static inline void on_wakeup( lock_type & this, size_t recursion ) {}
     80    static inline void on_wakeup( lock_type & /*this*/, size_t /*recursion*/ ) {}
    8181
    8282
     
    8787        __spinlock_t lock;
    8888        int count;
    89         __queue_t(thread$) waiting;
    90 };
    91 
    92 void  ?{}(semaphore & this, int count = 1);
    93 void ^?{}(semaphore & this);
    94 bool   P (semaphore & this);
    95 bool   V (semaphore & this);
    96 bool   V (semaphore & this, unsigned count);
    97 thread$ * V (semaphore & this, bool );
     89        __queue_t( thread$) waiting;
     90};
     91
     92void ?{}( semaphore & this, int count = 1 );
     93void ^?{}( semaphore & this );
     94bool P( semaphore & this );
     95bool V( semaphore & this );
     96bool V( semaphore & this, unsigned count );
     97thread$ * V( semaphore & this, bool );
    9898
    9999//----------
     
    102102};
    103103
    104 static inline void  ?{}( single_acquisition_lock & this ) {((blocking_lock &)this){ false, false };}
     104static inline void ?{}( single_acquisition_lock & this ) { ((blocking_lock &)this){ false, false }; }
    105105static inline void ^?{}( single_acquisition_lock & this ) {}
    106 static inline void   lock     ( single_acquisition_lock & this ) { lock    ( (blocking_lock &)this ); }
    107 static inline bool   try_lock ( single_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); }
    108 static inline void   unlock   ( single_acquisition_lock & this ) { unlock  ( (blocking_lock &)this ); }
    109 static inline size_t on_wait  ( single_acquisition_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum ); }
    110 static inline void   on_wakeup( single_acquisition_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
    111 static inline void   on_notify( single_acquisition_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); }
    112 static inline bool   register_select( single_acquisition_lock & this, select_node & node ) { return register_select( (blocking_lock &)this, node ); }
    113 static inline bool   unregister_select( single_acquisition_lock & this, select_node & node ) { return unregister_select( (blocking_lock &)this, node ); }
    114 static inline bool   on_selected( single_acquisition_lock & this, select_node & node ) { return on_selected( (blocking_lock &)this, node ); }
     106static inline void lock( single_acquisition_lock & this ) { lock( (blocking_lock &)this ); }
     107static inline bool try_lock( single_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); }
     108static inline void unlock( single_acquisition_lock & this ) { unlock( (blocking_lock &)this ); }
     109static inline size_t on_wait( single_acquisition_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum ); }
     110static inline void on_wakeup( single_acquisition_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
     111static inline void on_notify( single_acquisition_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); }
     112static inline bool register_select( single_acquisition_lock & this, select_node & node ) { return register_select( (blocking_lock &)this, node ); }
     113static inline bool unregister_select( single_acquisition_lock & this, select_node & node ) { return unregister_select( (blocking_lock &)this, node ); }
     114static inline bool on_selected( single_acquisition_lock & this, select_node & node ) { return on_selected( (blocking_lock &)this, node ); }
    115115__CFA_SELECT_GET_TYPE( single_acquisition_lock );
    116116
     
    120120};
    121121
    122 static inline void  ?{}( owner_lock & this ) {((blocking_lock &)this){ true, true };}
     122static inline void ?{}( owner_lock & this ) { ((blocking_lock &)this){ true, true }; }
    123123static inline void ^?{}( owner_lock & this ) {}
    124 static inline void   lock     ( owner_lock & this ) { lock    ( (blocking_lock &)this ); }
    125 static inline bool   try_lock ( owner_lock & this ) { return try_lock( (blocking_lock &)this ); }
    126 static inline void   unlock   ( owner_lock & this ) { unlock  ( (blocking_lock &)this ); }
    127 static inline size_t on_wait  ( owner_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum ); }
    128 static inline void   on_wakeup( owner_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
    129 static inline void   on_notify( owner_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); }
    130 static inline bool   register_select( owner_lock & this, select_node & node ) { return register_select( (blocking_lock &)this, node ); }
    131 static inline bool   unregister_select( owner_lock & this, select_node & node ) { return unregister_select( (blocking_lock &)this, node ); }
    132 static inline bool   on_selected( owner_lock & this, select_node & node ) { return on_selected( (blocking_lock &)this, node ); }
     124static inline void lock( owner_lock & this ) { lock( (blocking_lock &)this ); }
     125static inline bool try_lock( owner_lock & this ) { return try_lock( (blocking_lock &)this ); }
     126static inline void unlock( owner_lock & this ) { unlock( (blocking_lock &)this ); }
     127static inline size_t on_wait( owner_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) { return on_wait ( (blocking_lock &)this, pp_fn, pp_datum ); }
     128static inline void on_wakeup( owner_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); }
     129static inline void on_notify( owner_lock & this, struct thread$ * t ) { on_notify( (blocking_lock &)this, t ); }
     130static inline bool register_select( owner_lock & this, select_node & node ) { return register_select( (blocking_lock &)this, node ); }
     131static inline bool unregister_select( owner_lock & this, select_node & node ) { return unregister_select( (blocking_lock &)this, node ); }
     132static inline bool on_selected( owner_lock & this, select_node & node ) { return on_selected( (blocking_lock &)this, node ); }
    133133__CFA_SELECT_GET_TYPE( owner_lock );
    134134
     
    147147
    148148struct mcs_lock {
    149         mcs_queue(mcs_node) queue;
     149        mcs_queue( mcs_node ) queue;
    150150};
    151151
    152152static inline void lock( mcs_lock & l, mcs_node & n ) {
    153         if(push(l.queue, &n))
    154                 wait(n.sem);
    155 }
    156 
    157 static inline void unlock(mcs_lock & l, mcs_node & n) {
    158         mcs_node * next = advance(l.queue, &n);
    159         if(next) post(next->sem);
     153        if ( push( l.queue, &n ) )
     154                wait( n.sem );
     155}
     156
     157static inline void unlock( mcs_lock & l, mcs_node & n ) {
     158        mcs_node * next = advance( l.queue, &n );
     159        if ( next ) post( next->sem );
    160160}
    161161
     
    183183    n.locked = true;
    184184
    185         #if defined(__ARM_ARCH)
     185        #if defined( __ARM_ARCH )
    186186        __asm__ __volatile__ ( "DMB ISH" ::: );
    187187        #endif
    188188
    189         mcs_spin_node * prev = __atomic_exchange_n(&l.queue.tail, &n, __ATOMIC_SEQ_CST);
    190         if( prev == 0p ) return;
     189        mcs_spin_node * prev = __atomic_exchange_n( &l.queue.tail, &n, __ATOMIC_SEQ_CST );
     190        if ( prev == 0p ) return;
    191191        prev->next = &n;
    192192       
    193         #if defined(__ARM_ARCH)
     193        #if defined( __ARM_ARCH )
    194194        __asm__ __volatile__ ( "DMB ISH" ::: );
    195195        #endif
    196196
    197         while( __atomic_load_n(&n.locked, __ATOMIC_RELAXED) ) Pause();
    198 
    199         #if defined(__ARM_ARCH)
     197        while ( __atomic_load_n( &n.locked, __ATOMIC_RELAXED ) ) Pause();
     198
     199        #if defined( __ARM_ARCH )
    200200        __asm__ __volatile__ ( "DMB ISH" ::: );
    201201        #endif
    202202}
    203203
    204 static inline void unlock(mcs_spin_lock & l, mcs_spin_node & n) {
    205         #if defined(__ARM_ARCH)
     204static inline void unlock( mcs_spin_lock & l, mcs_spin_node & n ) {
     205        #if defined( __ARM_ARCH )
    206206        __asm__ __volatile__ ( "DMB ISH" ::: );
    207207        #endif
    208208
    209209        mcs_spin_node * n_ptr = &n;
    210         if (__atomic_compare_exchange_n(&l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) return;
    211         while (__atomic_load_n(&n.next, __ATOMIC_RELAXED) == 0p) Pause();
    212 
    213         #if defined(__ARM_ARCH)
     210        if ( __atomic_compare_exchange_n( &l.queue.tail, &n_ptr, 0p, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ) ) return;
     211        while ( __atomic_load_n( &n.next, __ATOMIC_RELAXED ) == 0p ) Pause();
     212
     213        #if defined( __ARM_ARCH )
    214214        __asm__ __volatile__ ( "DMB ISH" ::: );
    215215        #endif
     
    233233
    234234// to use for FUTEX_WAKE and FUTEX_WAIT (other futex calls will need more params)
    235 static inline int futex(int *uaddr, int futex_op, int val) {
    236     return syscall(SYS_futex, uaddr, futex_op, val, NULL, NULL, 0);
    237 }
    238 
    239 static inline void ?{}( futex_mutex & this ) with(this) { val = 0; }
    240 
    241 static inline bool internal_try_lock( futex_mutex & this, int & compare_val) with(this) {
    242         return __atomic_compare_exchange_n((int*)&val, (int*)&compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
    243 }
    244 
    245 static inline int internal_exchange( futex_mutex & this ) with(this) {
    246         return __atomic_exchange_n((int*)&val, 2, __ATOMIC_ACQUIRE);
     235static inline int futex( int *uaddr, int futex_op, int val ) {
     236    return syscall( SYS_futex, uaddr, futex_op, val, NULL, NULL, 0 );
     237}
     238
     239static inline void ?{}( futex_mutex & this ) with( this ) { val = 0; }
     240
     241static inline bool internal_try_lock( futex_mutex & this, int & compare_val ) with( this ) {
     242        return __atomic_compare_exchange_n( (int*)&val, (int*)&compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE );
     243}
     244
     245static inline int internal_exchange( futex_mutex & this ) with( this ) {
     246        return __atomic_exchange_n(( int*)&val, 2, __ATOMIC_ACQUIRE );
    247247}
    248248
    249249// if this is called recursively IT WILL DEADLOCK!!!!!
    250 static inline void lock( futex_mutex & this ) with(this) {
     250static inline void lock( futex_mutex & this ) with( this ) {
    251251        int state;
    252252
    253         for( int spin = 4; spin < 1024; spin += spin) {
     253        for ( spin; 4 ~ 1024 ~ spin ) {
    254254                state = 0;
    255255                // if unlocked, lock and return
    256                 if (internal_try_lock(this, state)) return;
    257                 if (2 == state) break;
    258                 for (int i = 0; i < spin; i++) Pause();
     256                if ( internal_try_lock( this, state ) ) return;
     257                if ( state == 2 ) break;
     258                for ( spin ) Pause();
    259259        }
    260260       
    261261        // if not in contended state, set to be in contended state
    262         if (state != 2) state = internal_exchange(this);
     262        if ( state != 2 ) state = internal_exchange( this );
    263263
    264264        // block and spin until we win the lock
    265         while (state != 0) {
    266                 futex((int*)&val, FUTEX_WAIT, 2); // if val is not 2 this returns with EWOULDBLOCK
    267                 state = internal_exchange(this);
    268         }
    269 }
    270 
    271 static inline void unlock(futex_mutex & this) with(this) {
     265        while ( state != 0 ) {
     266                futex( (int*)&val, FUTEX_WAIT, 2 ); // if val is not 2 this returns with EWOULDBLOCK
     267                state = internal_exchange( this );
     268        }
     269}
     270
     271static inline void unlock( futex_mutex & this ) with( this ) {
    272272        // if uncontended do atomic unlock and then return
    273     if (__atomic_exchange_n(&val, 0, __ATOMIC_RELEASE) == 1) return;
     273    if ( __atomic_exchange_n( &val, 0, __ATOMIC_RELEASE ) == 1 ) return;
    274274       
    275275        // otherwise threads are blocked so we must wake one
    276         futex((int *)&val, FUTEX_WAKE, 1);
     276        futex(( int *)&val, FUTEX_WAKE, 1 );
    277277}
    278278
     
    295295        int val;
    296296};
    297 static inline void  ?{}( go_mutex & this ) with(this) { val = 0; }
     297static inline void  ?{}( go_mutex & this ) with( this ) { val = 0; }
    298298static inline void ?{}( go_mutex & this, go_mutex this2 ) = void;
    299299static inline void ?=?( go_mutex & this, go_mutex this2 ) = void;
    300300
    301 static inline bool internal_try_lock(go_mutex & this, int & compare_val, int new_val ) with(this) {
    302         return __atomic_compare_exchange_n((int*)&val, (int*)&compare_val, new_val, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
    303 }
    304 
    305 static inline int internal_exchange(go_mutex & this, int swap ) with(this) {
    306         return __atomic_exchange_n((int*)&val, swap, __ATOMIC_ACQUIRE);
     301static inline bool internal_try_lock( go_mutex & this, int & compare_val, int new_val ) with( this ) {
     302        return __atomic_compare_exchange_n( (int*)&val, (int*)&compare_val, new_val, false, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE );
     303}
     304
     305static inline int internal_exchange( go_mutex & this, int swap ) with( this ) {
     306        return __atomic_exchange_n( (int*)&val, swap, __ATOMIC_ACQUIRE );
    307307}
    308308
     
    312312
    313313    // speculative grab
    314     state = internal_exchange(this, 1);
    315     if ( !state ) return; // state == 0
     314    state = internal_exchange( this, 1 );
     315    if ( ! state ) return;                                                              // state == 0
    316316    init_state = state;
    317     for (;;) {
    318         for( int i = 0; i < 4; i++ ) {
    319             while( !val ) { // lock unlocked
     317    for () {
     318        for ( 4 ) {
     319            while ( ! val ) {                                                   // lock unlocked
    320320                state = 0;
    321321                if ( internal_try_lock( this, state, init_state ) ) return;
    322322            }
    323             for (int i = 0; i < 30; i++) Pause();
     323            for ( 30 ) Pause();
    324324        }
    325325
    326         while( !val ) { // lock unlocked
     326        while ( ! val ) {                                                               // lock unlocked
    327327            state = 0;
    328328            if ( internal_try_lock( this, state, init_state ) ) return;
     
    332332        // if not in contended state, set to be in contended state
    333333        state = internal_exchange( this, 2 );
    334         if ( !state ) return; // state == 0
     334        if ( ! state ) return;                                                  // state == 0
    335335        init_state = 2;
    336         futex( (int*)&val, FUTEX_WAIT, 2 ); // if val is not 2 this returns with EWOULDBLOCK
     336        futex( (int*)&val, FUTEX_WAIT, 2 );                             // if val is not 2 this returns with EWOULDBLOCK
    337337    }
    338338}
    339339
    340 static inline void unlock( go_mutex & this ) with(this) {
     340static inline void unlock( go_mutex & this ) with( this ) {
    341341        // if uncontended do atomic unlock and then return
    342     if ( __atomic_exchange_n(&val, 0, __ATOMIC_RELEASE) == 1 ) return;
     342    if ( __atomic_exchange_n( &val, 0, __ATOMIC_RELEASE ) == 1 ) return;
    343343       
    344344        // otherwise threads are blocked so we must wake one
     
    373373static inline void  ^?{}( exp_backoff_then_block_lock & this ){}
    374374
    375 static inline bool internal_try_lock( exp_backoff_then_block_lock & this, size_t & compare_val ) with(this) {
    376         return __atomic_compare_exchange_n(&lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED);
     375static inline bool internal_try_lock( exp_backoff_then_block_lock & this, size_t & compare_val ) with( this ) {
     376        return __atomic_compare_exchange_n( &lock_value, &compare_val, 1, false, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED );
    377377}
    378378
    379379static inline bool try_lock( exp_backoff_then_block_lock & this ) { size_t compare_val = 0; return internal_try_lock( this, compare_val ); }
    380380
    381 static inline bool try_lock_contention( exp_backoff_then_block_lock & this ) with(this) {
    382         return !__atomic_exchange_n( &lock_value, 2, __ATOMIC_ACQUIRE );
    383 }
    384 
    385 static inline bool block( exp_backoff_then_block_lock & this ) with(this) {
     381static inline bool try_lock_contention( exp_backoff_then_block_lock & this ) with( this ) {
     382        return ! __atomic_exchange_n( &lock_value, 2, __ATOMIC_ACQUIRE );
     383}
     384
     385static inline bool block( exp_backoff_then_block_lock & this ) with( this ) {
    386386    lock( spinlock __cfaabi_dbg_ctx2 );
    387     if (__atomic_load_n( &lock_value, __ATOMIC_SEQ_CST) != 2) {
     387    if ( __atomic_load_n( &lock_value, __ATOMIC_SEQ_CST ) != 2 ) {
    388388        unlock( spinlock );
    389389        return true;
     
    395395}
    396396
    397 static inline void lock( exp_backoff_then_block_lock & this ) with(this) {
     397static inline void lock( exp_backoff_then_block_lock & this ) with( this ) {
    398398        size_t compare_val = 0;
    399399        int spin = 4;
    400400
    401401        // linear backoff
    402         for( ;; ) {
     402        for () {
    403403                compare_val = 0;
    404                 if (internal_try_lock(this, compare_val)) return;
    405                 if (2 == compare_val) break;
    406                 for (int i = 0; i < spin; i++) Pause();
    407                 if (spin >= 1024) break;
     404                if ( internal_try_lock( this, compare_val ) ) return;
     405                if ( compare_val == 2 ) break;
     406                for ( spin ) Pause();
     407                if ( spin >= 1024 ) break;
    408408                spin += spin;
    409409        }
    410410
    411         if(2 != compare_val && try_lock_contention(this)) return;
     411        if ( 2 != compare_val && try_lock_contention( this ) ) return;
    412412        // block until signalled
    413         while (block(this)) if(try_lock_contention(this)) return;
    414 }
    415 
    416 static inline void unlock( exp_backoff_then_block_lock & this ) with(this) {
    417     if (__atomic_exchange_n(&lock_value, 0, __ATOMIC_RELEASE) == 1) return;
     413        while ( block( this ) ) if ( try_lock_contention( this ) ) return;
     414}
     415
     416static inline void unlock( exp_backoff_then_block_lock & this ) with( this ) {
     417    if ( __atomic_exchange_n( &lock_value, 0, __ATOMIC_RELEASE ) == 1 ) return;
    418418    lock( spinlock __cfaabi_dbg_ctx2 );
    419419    thread$ * t = &try_pop_front( blocked_threads );
     
    444444};
    445445
    446 static inline void  ?{}( fast_block_lock & this ) with(this) {
     446static inline void  ?{}( fast_block_lock & this ) with( this ) {
    447447        lock{};
    448448        blocked_threads{};
     
    454454
    455455// if this is called recursively IT WILL DEADLOCK!!!!!
    456 static inline void lock( fast_block_lock & this ) with(this) {
     456static inline void lock( fast_block_lock & this ) with( this ) {
    457457        lock( lock __cfaabi_dbg_ctx2 );
    458458        if ( held ) {
     
    466466}
    467467
    468 static inline void unlock( fast_block_lock & this ) with(this) {
     468static inline void unlock( fast_block_lock & this ) with( this ) {
    469469        lock( lock __cfaabi_dbg_ctx2 );
    470470        /* paranoid */ verifyf( held != false, "Attempt to release lock %p that isn't held", &this );
     
    475475}
    476476
    477 static inline void on_notify( fast_block_lock & this, struct thread$ * t ) with(this) {
     477static inline void on_notify( fast_block_lock & this, struct thread$ * t ) with( this ) {
    478478    lock( lock __cfaabi_dbg_ctx2 );
    479479    insert_last( blocked_threads, *t );
     
    503503};
    504504
    505 static inline void  ?{}( simple_owner_lock & this ) with(this) {
     505static inline void  ?{}( simple_owner_lock & this ) with( this ) {
    506506        lock{};
    507507        blocked_threads{};
     
    513513static inline void ?=?( simple_owner_lock & this, simple_owner_lock this2 ) = void;
    514514
    515 static inline void lock( simple_owner_lock & this ) with(this) {
     515static inline void lock( simple_owner_lock & this ) with( this ) {
    516516        if ( owner == active_thread() ) {
    517517                recursion_count++;
     
    532532}
    533533
    534 static inline void pop_node( simple_owner_lock & this ) with(this) {
     534static inline void pop_node( simple_owner_lock & this ) with( this ) {
    535535    __handle_waituntil_OR( blocked_threads );
    536536    select_node * node = &try_pop_front( blocked_threads );
     
    538538        owner = node->blocked_thread;
    539539        recursion_count = 1;
    540         // if ( !node->clause_status || __make_select_node_available( *node ) ) unpark( node->blocked_thread );
     540        // if ( ! node->clause_status || __make_select_node_available( *node ) ) unpark( node->blocked_thread );
    541541        wake_one( blocked_threads, *node );
    542542    } else {
     
    546546}
    547547
    548 static inline void unlock( simple_owner_lock & this ) with(this) {
     548static inline void unlock( simple_owner_lock & this ) with( this ) {
    549549        lock( lock __cfaabi_dbg_ctx2 );
    550550        /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );
     
    558558}
    559559
    560 static inline void on_notify( simple_owner_lock & this, thread$ * t ) with(this) {
     560static inline void on_notify( simple_owner_lock & this, thread$ * t ) with( this ) {
    561561        lock( lock __cfaabi_dbg_ctx2 );
    562562        // lock held
     
    573573}
    574574
    575 static inline size_t on_wait( simple_owner_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) with(this) {
     575static inline size_t on_wait( simple_owner_lock & this, __cfa_pre_park pp_fn, void * pp_datum ) with( this ) {
    576576        lock( lock __cfaabi_dbg_ctx2 );
    577577        /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this );
     
    591591}
    592592
    593 static inline void on_wakeup( simple_owner_lock & this, size_t recursion ) with(this) { recursion_count = recursion; }
     593static inline void on_wakeup( simple_owner_lock & this, size_t recursion ) with( this ) { recursion_count = recursion; }
    594594
    595595// waituntil() support
    596 static inline bool register_select( simple_owner_lock & this, select_node & node ) with(this) {
     596static inline bool register_select( simple_owner_lock & this, select_node & node ) with( this ) {
    597597    lock( lock __cfaabi_dbg_ctx2 );
    598598
    599599    // check if we can complete operation. If so race to establish winner in special OR case
    600     if ( !node.park_counter && ( owner == active_thread() || owner == 0p ) ) {
    601         if ( !__make_select_node_available( node ) ) { // we didn't win the race so give up on registering
     600    if ( ! node.park_counter && ( owner == active_thread() || owner == 0p ) ) {
     601        if ( ! __make_select_node_available( node ) ) { // we didn't win the race so give up on registering
    602602           unlock( lock );
    603603           return false;
     
    626626}
    627627
    628 static inline bool unregister_select( simple_owner_lock & this, select_node & node ) with(this) {
     628static inline bool unregister_select( simple_owner_lock & this, select_node & node ) with( this ) {
    629629    lock( lock __cfaabi_dbg_ctx2 );
    630630    if ( node`isListed ) {
     
    644644}
    645645
    646 static inline bool on_selected( simple_owner_lock & this, select_node & node ) { return true; }
     646static inline bool on_selected( simple_owner_lock & /*this*/, select_node & /*node*/ ) { return true; }
    647647__CFA_SELECT_GET_TYPE( simple_owner_lock );
    648648
     
    662662};
    663663
    664 static inline void  ?{}( spin_queue_lock & this ) with(this) {
     664static inline void  ?{}( spin_queue_lock & this ) with( this ) {
    665665        lock{};
    666666        held = false;
     
    671671
    672672// if this is called recursively IT WILL DEADLOCK!
    673 static inline void lock( spin_queue_lock & this ) with(this) {
     673static inline void lock( spin_queue_lock & this ) with( this ) {
    674674        mcs_spin_node node;
    675675        lock( lock, node );
    676         while(__atomic_load_n(&held, __ATOMIC_SEQ_CST)) Pause();
    677         __atomic_store_n(&held, true, __ATOMIC_SEQ_CST);
     676        while ( __atomic_load_n( &held, __ATOMIC_SEQ_CST ) ) Pause();
     677        __atomic_store_n( &held, true, __ATOMIC_SEQ_CST );
    678678        unlock( lock, node );
    679679}
    680680
    681 static inline void unlock( spin_queue_lock & this ) with(this) {
    682         __atomic_store_n(&held, false, __ATOMIC_RELEASE);
     681static inline void unlock( spin_queue_lock & this ) with( this ) {
     682        __atomic_store_n( &held, false, __ATOMIC_RELEASE );
    683683}
    684684
     
    702702};
    703703
    704 static inline void  ?{}( mcs_block_spin_lock & this ) with(this) {
     704static inline void  ?{}( mcs_block_spin_lock & this ) with( this ) {
    705705        lock{};
    706706        held = false;
     
    711711
    712712// if this is called recursively IT WILL DEADLOCK!!!!!
    713 static inline void lock( mcs_block_spin_lock & this ) with(this) {
     713static inline void lock( mcs_block_spin_lock & this ) with( this ) {
    714714        mcs_node node;
    715715        lock( lock, node );
    716         while(__atomic_load_n(&held, __ATOMIC_SEQ_CST)) Pause();
    717         __atomic_store_n(&held, true, __ATOMIC_SEQ_CST);
     716        while ( __atomic_load_n( &held, __ATOMIC_SEQ_CST ) ) Pause();
     717        __atomic_store_n( &held, true, __ATOMIC_SEQ_CST );
    718718        unlock( lock, node );
    719719}
    720720
    721 static inline void unlock(mcs_block_spin_lock & this) with(this) {
    722         __atomic_store_n(&held, false, __ATOMIC_SEQ_CST);
     721static inline void unlock( mcs_block_spin_lock & this ) with( this ) {
     722        __atomic_store_n( &held, false, __ATOMIC_SEQ_CST );
    723723}
    724724
     
    742742};
    743743
    744 static inline void  ?{}( block_spin_lock & this ) with(this) {
     744static inline void  ?{}( block_spin_lock & this ) with( this ) {
    745745        lock{};
    746746        held = false;
     
    751751
    752752// if this is called recursively IT WILL DEADLOCK!!!!!
    753 static inline void lock( block_spin_lock & this ) with(this) {
     753static inline void lock( block_spin_lock & this ) with( this ) {
    754754        lock( lock );
    755         while(__atomic_load_n(&held, __ATOMIC_SEQ_CST)) Pause();
    756         __atomic_store_n(&held, true, __ATOMIC_RELEASE);
     755        while ( __atomic_load_n( &held, __ATOMIC_SEQ_CST ) ) Pause();
     756        __atomic_store_n( &held, true, __ATOMIC_RELEASE );
    757757        unlock( lock );
    758758}
    759759
    760 static inline void unlock( block_spin_lock & this ) with(this) {
    761         __atomic_store_n(&held, false, __ATOMIC_RELEASE);
    762 }
    763 
    764 static inline void on_notify( block_spin_lock & this, struct thread$ * t ) with(this.lock) {
     760static inline void unlock( block_spin_lock & this ) with( this ) {
     761        __atomic_store_n( &held, false, __ATOMIC_RELEASE );
     762}
     763
     764static inline void on_notify( block_spin_lock & this, struct thread$ * t ) with( this.lock ) {
    765765        // first we acquire internal fast_block_lock
    766766        lock( lock __cfaabi_dbg_ctx2 );
     
    774774        unlock( lock );
    775775
    776         unpark(t);
     776        unpark( t );
    777777}
    778778DEFAULT_ON_WAIT( block_spin_lock )
    779 static inline void on_wakeup( block_spin_lock & this, size_t recursion ) with(this) {
     779        static inline void on_wakeup( block_spin_lock & this, size_t /*recursion*/ ) with( this ) {
    780780        // now we acquire the entire block_spin_lock upon waking up
    781         while(__atomic_load_n(&held, __ATOMIC_SEQ_CST)) Pause();
    782         __atomic_store_n(&held, true, __ATOMIC_RELEASE);
     781        while ( __atomic_load_n( &held, __ATOMIC_SEQ_CST ) ) Pause();
     782        __atomic_store_n( &held, true, __ATOMIC_RELEASE );
    783783        unlock( lock ); // Now we release the internal fast_spin_lock
    784784}
     
    788788// // the info thread is a wrapper around a thread used
    789789// // to store extra data for use in the condition variable
    790 forall(L & | is_blocking_lock(L)) {
     790forall( L & | is_blocking_lock( L ) ) {
    791791        struct info_thread;
    792792}
     
    794794//-----------------------------------------------------------------------------
    795795// Synchronization Locks
    796 forall(L & | is_blocking_lock(L)) {
     796forall( L & | is_blocking_lock( L ) ) {
    797797
    798798        //-----------------------------------------------------------------------------
     
    810810
    811811                // List of blocked threads
    812                 dlist( info_thread(L) ) blocked_threads;
     812                dlist( info_thread( L ) ) blocked_threads;
    813813
    814814                // Count of current blocked threads
     
    816816        };
    817817
    818 
    819         void  ?{}( condition_variable(L) & this );
    820         void ^?{}( condition_variable(L) & this );
    821 
    822         bool notify_one( condition_variable(L) & this );
    823         bool notify_all( condition_variable(L) & this );
    824 
    825         uintptr_t front( condition_variable(L) & this );
    826 
    827         bool empty  ( condition_variable(L) & this );
    828         int  counter( condition_variable(L) & this );
    829 
    830         void wait( condition_variable(L) & this );
    831         void wait( condition_variable(L) & this, uintptr_t info );
    832         bool wait( condition_variable(L) & this, Duration duration );
    833         bool wait( condition_variable(L) & this, uintptr_t info, Duration duration );
    834 
    835         void wait( condition_variable(L) & this, L & l );
    836         void wait( condition_variable(L) & this, L & l, uintptr_t info );
    837         bool wait( condition_variable(L) & this, L & l, Duration duration );
    838         bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );
     818        void ?{}( condition_variable( L ) & this );
     819        void ^?{}( condition_variable( L ) & this );
     820
     821        bool notify_one( condition_variable( L ) & this );
     822        bool notify_all( condition_variable( L ) & this );
     823
     824        uintptr_t front( condition_variable( L ) & this );
     825
     826        bool empty  ( condition_variable( L ) & this );
     827        int  counter( condition_variable( L ) & this );
     828
     829        void wait( condition_variable( L ) & this );
     830        void wait( condition_variable( L ) & this, uintptr_t info );
     831        bool wait( condition_variable( L ) & this, Duration duration );
     832        bool wait( condition_variable( L ) & this, uintptr_t info, Duration duration );
     833
     834        void wait( condition_variable( L ) & this, L & l );
     835        void wait( condition_variable( L ) & this, L & l, uintptr_t info );
     836        bool wait( condition_variable( L ) & this, L & l, Duration duration );
     837        bool wait( condition_variable( L ) & this, L & l, uintptr_t info, Duration duration );
    839838
    840839        //-----------------------------------------------------------------------------
     
    848847        struct fast_cond_var {
    849848                // List of blocked threads
    850                 dlist( info_thread(L) ) blocked_threads;
     849                dlist( info_thread( L ) ) blocked_threads;
    851850                #ifdef __CFA_DEBUG__
    852851                L * lock_used;
     
    854853        };
    855854
    856         void  ?{}( fast_cond_var(L) & this );
    857         void ^?{}( fast_cond_var(L) & this );
    858 
    859         bool notify_one( fast_cond_var(L) & this );
    860         bool notify_all( fast_cond_var(L) & this );
    861 
    862         uintptr_t front( fast_cond_var(L) & this );
    863         bool empty  ( fast_cond_var(L) & this );
    864 
    865         void wait( fast_cond_var(L) & this, L & l );
    866         void wait( fast_cond_var(L) & this, L & l, uintptr_t info );
     855        void ?{}( fast_cond_var( L ) & this );
     856        void ^?{}( fast_cond_var( L ) & this );
     857
     858        bool notify_one( fast_cond_var( L ) & this );
     859        bool notify_all( fast_cond_var( L ) & this );
     860
     861        uintptr_t front( fast_cond_var( L ) & this );
     862        bool empty  ( fast_cond_var( L ) & this );
     863
     864        void wait( fast_cond_var( L ) & this, L & l );
     865        void wait( fast_cond_var( L ) & this, L & l, uintptr_t info );
    867866
    868867
     
    874873
    875874        struct pthread_cond_var {
    876                 dlist( info_thread(L) ) blocked_threads;
     875                dlist( info_thread( L ) ) blocked_threads;
    877876                __spinlock_t lock;
    878877        };
    879878
    880         void  ?{}( pthread_cond_var(L) & this );
    881         void ^?{}( pthread_cond_var(L) & this );
    882 
    883         bool notify_one( pthread_cond_var(L) & this );
    884         bool notify_all( pthread_cond_var(L) & this );
    885 
    886         uintptr_t front( pthread_cond_var(L) & this );
    887         bool empty ( pthread_cond_var(L) & this );
    888 
    889         void wait( pthread_cond_var(L) & this, L & l );
    890         void wait( pthread_cond_var(L) & this, L & l, uintptr_t info );
    891         bool wait( pthread_cond_var(L) & this, L & l, timespec t );
    892         bool wait( pthread_cond_var(L) & this, L & l, uintptr_t info, timespec t );
    893 }
     879        void  ?{}( pthread_cond_var( L ) & this );
     880        void ^?{}( pthread_cond_var( L ) & this );
     881
     882        bool notify_one( pthread_cond_var( L ) & this );
     883        bool notify_all( pthread_cond_var( L ) & this );
     884
     885        uintptr_t front( pthread_cond_var( L ) & this );
     886        bool empty ( pthread_cond_var( L ) & this );
     887
     888        void wait( pthread_cond_var( L ) & this, L & l );
     889        void wait( pthread_cond_var( L ) & this, L & l, uintptr_t info );
     890        bool wait( pthread_cond_var( L ) & this, L & l, timespec t );
     891        bool wait( pthread_cond_var( L ) & this, L & l, uintptr_t info, timespec t );
     892}
  • TabularUnified libcfa/src/concurrency/select.hfa

    r4f4ae60 ra6b48f6  
    184184
    185185// wake one thread from the list
    186 static inline void wake_one( dlist( select_node ) & queue, select_node & popped ) {
     186static inline void wake_one( dlist( select_node ) & /*queue*/, select_node & popped ) {
    187187    if ( !popped.clause_status                              // normal case, node is not a select node
    188188        || ( popped.clause_status && !popped.park_counter ) // If popped link is special case OR selecting unpark but don't call __make_select_node_available
Note: See TracChangeset for help on using the changeset viewer.