diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-02-28 16:11:42 -0500 | 
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-02-28 16:50:49 -0500 | 
| commit | f765d422d1b54f51d3735dcc584efd714007f6e2 (patch) | |
| tree | 95d5c5d84eda6c6113f6ff16e03cf74c8bc34621 /lib/frratomic.h | |
| parent | 85121506e7b27be48dd9c0d95eaff215947b2b26 (diff) | |
lib: add atomic bitwise OR, AND
* Add support for C11 bitwise OR & AND operations
* Add atomic versions of bitfield macros
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/frratomic.h')
| -rw-r--r-- | lib/frratomic.h | 16 | 
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/frratomic.h b/lib/frratomic.h index 4ae84c4018..689b25255d 100644 --- a/lib/frratomic.h +++ b/lib/frratomic.h @@ -46,6 +46,8 @@  #define atomic_exchange_explicit __atomic_exchange_n  #define atomic_fetch_add_explicit __atomic_fetch_add  #define atomic_fetch_sub_explicit __atomic_fetch_sub +#define atomic_fetch_and_explicit __atomic_fetch_and +#define atomic_fetch_or_explicit __atomic_fetch_or  #define atomic_compare_exchange_weak_explicit(atom, expect, desire, mem1,      \  					      mem2)                            \ @@ -135,6 +137,20 @@  		*_expect = rval;                                               \  		ret;                                                           \  	}) +#define atomic_fetch_and_explicit(ptr, val, mem)                               \ +	({                                                                     \ +		__sync_synchronize();                                          \ +		typeof(*ptr) rval = __sync_fetch_and_and(ptr, val);            \ +		__sync_synchronize();                                          \ +		rval;                                                          \ +	}) +#define atomic_fetch_or_explicit(ptr, val, mem)                                \ +	({                                                                     \ +		__sync_synchronize();                                          \ +		typeof(*ptr) rval = __sync_fetch_and_or(ptr, val);             \ +		__sync_synchronize();                                          \ +		rval;                                                          \ +	})  #else /* !HAVE___ATOMIC && !HAVE_STDATOMIC_H */  #error no atomic functions...  | 
