Ignore:
Timestamp:
Jun 9, 2023, 2:28:12 PM (19 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ast-experimental, master
Children:
01fac29
Parents:
b301a82
Message:

update short atomic macros

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/atomic.hfa

    rb301a82 re6c9115  
    1010// Created On       : Thu May 25 15:22:46 2023
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 25 15:24:45 2023
    13 // Update Count     : 1
     12// Last Modified On : Fri Jun  9 13:36:47 2023
     13// Update Count     : 46
    1414//
    1515
    16 #define LOAD( lock ) (__atomic_load_n( &(lock), __ATOMIC_SEQ_CST ))
    17 #define LOADM( lock, memorder ) (__atomic_load_n( &(lock), memorder ))
    18 #define STORE( lock, assn ) (__atomic_store_n( &(lock), assn, __ATOMIC_SEQ_CST ))
    19 #define STOREM( lock, assn, memorder ) (__atomic_store_n( &(lock), assn, memorder ))
    20 #define CLR( lock ) (__atomic_clear( &(lock), __ATOMIC_RELEASE ))
    21 #define CLRM( lock, memorder ) (__atomic_clear( &(lock), memorder ))
    22 #define TAS( lock ) (__atomic_test_and_set( &(lock), __ATOMIC_ACQUIRE ))
    23 #define TASM( lock, memorder ) (__atomic_test_and_set( &(lock), memorder ))
    24 #define CAS( change, comp, assn ) ({typeof(comp) __temp = (comp); __atomic_compare_exchange_n( &(change), &(__temp), (assn), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ); })
    25 #define CASM( change, comp, assn, memorder... ) ({typeof(comp) * __temp = &(comp); __atomic_compare_exchange_n( &(change), &(__temp), (assn), false, memorder, memorder ); })
    26 #define CASV( change, comp, assn ) (__atomic_compare_exchange_n( &(change), &(comp), (assn), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ))
    27 #define CASVM( change, comp, assn, memorder... ) (__atomic_compare_exchange_n( &(change), &(comp), (assn), false, memorder, memorder ))
    28 #define FAS( change, assn ) (__atomic_exchange_n( &(change), (assn), __ATOMIC_SEQ_CST ))
    29 #define FASM( change, assn, memorder ) (__atomic_exchange_n( &(change), (assn), memorder ))
    30 #define FAI( change, Inc ) (__atomic_fetch_add( &(change), (Inc), __ATOMIC_SEQ_CST ))
    31 #define FAIM( change, Inc, memorder ) (__atomic_fetch_add( &(change), (Inc), memorder ))
     16#define LOAD( val ) (LOADM( val, __ATOMIC_SEQ_CST))
     17#define LOADM( val, memorder ) (__atomic_load_n( &(val), memorder))
     18
     19#define STORE( val, assn ) (STOREM( val, assn, __ATOMIC_SEQ_CST))
     20#define STOREM( val, assn, memorder ) (__atomic_store_n( &(val), assn, memorder))
     21
     22#define TAS( lock ) (TASM( lock, __ATOMIC_ACQUIRE))
     23#define TASM( lock, memorder ) (__atomic_test_and_set( &(lock), memorder))
     24
     25#define TASCLR( lock ) (TASCLRM( lock, __ATOMIC_RELEASE))
     26#define TASCLRM( lock, memorder ) (__atomic_clear( &(lock), memorder))
     27
     28#define FAS( assn, replace ) (FASM(assn, replace, __ATOMIC_SEQ_CST))
     29#define FASM( assn, replace, memorder ) (__atomic_exchange_n( &(assn), (replace), memorder))
     30
     31#define FAI( assn, Inc ) (__atomic_fetch_add( &(assn), (Inc), __ATOMIC_SEQ_CST))
     32#define FAIM( assn, Inc, memorder ) (__atomic_fetch_add( &(assn), (Inc), memorder))
     33
     34// Use __sync because __atomic with 128-bit CAA can result in calls to pthread_mutex_lock.
     35
     36// #define CAS( assn, comp, replace ) (CASM( assn, comp, replace, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
     37// #define CASM( assn, comp, replace, memorder... ) ({ \
     38//      typeof(comp) __temp = (comp); \
     39//      __atomic_compare_exchange_n( &(assn), &(__temp), (replace), false, memorder ); \
     40// })
     41#define CAS( assn, comp, replace ) (__sync_bool_compare_and_swap( &assn, comp, replace))
     42#define CASM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CAS macro" );
     43
     44// #define CASV( assn, comp, replace ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ))
     45// #define CASVM( assn, comp, replace, memorder... ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, memorder, memorder ))
     46#define CASV( assn, comp, replace ) ({ \
     47        typeof(comp) temp = comp; \
     48        typeof(comp) old = __sync_val_compare_and_swap( &(assn), (comp), (replace) ); \
     49        old == temp ? true : (comp = old, false); \
     50})
     51#define CASVM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CASV macro" );
Note: See TracChangeset for help on using the changeset viewer.