source: libcfa/src/concurrency/atomic.hfa @ 0139351

Last change on this file since 0139351 was 4f9d75d, checked in by Peter A. Buhr <pabuhr@…>, 17 months ago

formatting

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[8463136]1//
2// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// atomic.hfa -- simpler macros to access atomic instructions
8//
9// Author           : Peter A. Buhr
10// Created On       : Thu May 25 15:22:46 2023
11// Last Modified By : Peter A. Buhr
[4f9d75d]12// Last Modified On : Wed Jun 14 07:48:57 2023
13// Update Count     : 52
[8463136]14//
15
[e6c9115]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))
[4f9d75d]37// #define CASM( assn, comp, replace, memorder... ) ({ typeof(comp) __temp = (comp); __atomic_compare_exchange_n( &(assn), &(__temp), (replace), false, memorder ); })
[e6c9115]38#define CAS( assn, comp, replace ) (__sync_bool_compare_and_swap( &assn, comp, replace))
39#define CASM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CAS macro" );
40
41// #define CASV( assn, comp, replace ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ))
42// #define CASVM( assn, comp, replace, memorder... ) (__atomic_compare_exchange_n( &(assn), &(comp), (replace), false, memorder, memorder ))
43#define CASV( assn, comp, replace ) ({ \
44        typeof(comp) temp = comp; \
45        typeof(comp) old = __sync_val_compare_and_swap( &(assn), (comp), (replace) ); \
46        old == temp ? true : (comp = old, false); \
47})
48#define CASVM( assn, comp, replace, memorder... ) _Static_assert( false, "memory order unsupported for CASV macro" );
Note: See TracBrowser for help on using the repository browser.