25 #ifndef DOZERG_ATOMIC_SYNC_H_20130117 26 #define DOZERG_ATOMIC_SYNC_H_20130117 30 #include "impl/environment.hh" 61 value_type
load()
const volatile{
62 return const_cast<__Myt *
>(
this)->
add_fetch(0);
69 static value_type
load(
const value_type * v){
71 return add_fetch(const_cast<value_type *>(v), 0);
85 static void store(value_type * v, value_type c){
95 value_type
fetch_add(value_type c)
volatile{
return __sync_fetch_and_add(&v_, c);}
103 static value_type
fetch_add(value_type * v, value_type c){
105 return __sync_fetch_and_add(v, c);
113 value_type
add_fetch(value_type c)
volatile{
return __sync_add_and_fetch(&v_, c);}
121 static value_type
add_fetch(value_type * v, value_type c){
123 return __sync_add_and_fetch (v, c);
131 value_type
fetch_sub(value_type c)
volatile{
return __sync_fetch_and_sub(&v_, c);}
139 static value_type
fetch_sub(value_type * v, value_type c){
141 return __sync_fetch_and_sub(v, c);
149 value_type
sub_fetch(value_type c)
volatile{
return __sync_sub_and_fetch(&v_, c);}
157 static value_type
sub_fetch(value_type * v, value_type c){
159 return __sync_sub_and_fetch (v, c);
167 value_type
fetch_or(value_type c)
volatile{
return __sync_fetch_and_or(&v_, c);}
175 static value_type
fetch_or(value_type * v, value_type c){
177 return __sync_fetch_and_or(v, c);
185 value_type
or_fetch(value_type c)
volatile{
return __sync_or_and_fetch(&v_, c);}
193 static value_type
or_fetch(value_type * v, value_type c){
195 return __sync_or_and_fetch (v, c);
203 value_type
fetch_and(value_type c)
volatile{
return __sync_fetch_and_and(&v_, c);}
211 static value_type
fetch_and(value_type * v, value_type c){
213 return __sync_fetch_and_and(v, c);
221 value_type
and_fetch(value_type c)
volatile{
return __sync_and_and_fetch(&v_, c);}
229 static value_type
and_fetch(value_type * v, value_type c){
231 return __sync_and_and_fetch (v, c);
239 value_type
fetch_xor(value_type c)
volatile{
return __sync_fetch_and_xor(&v_, c);}
247 static value_type
fetch_xor(value_type * v, value_type c){
249 return __sync_fetch_and_xor(v, c);
257 value_type
xor_fetch(value_type c)
volatile{
return __sync_xor_and_fetch(&v_, c);}
265 static value_type
xor_fetch(value_type * v, value_type c){
267 return __sync_xor_and_fetch (v, c);
275 value_type
swap(value_type c)
volatile{
return __sync_lock_test_and_set(&v_, c);}
283 static value_type
swap(value_type * v, value_type c){
285 return __sync_lock_test_and_set(v, c);
304 bool compare_swap(value_type expval, value_type newval, value_type * oldval = NULL)
volatile{
306 return __sync_bool_compare_and_swap(&v_, expval, newval);
307 *oldval = __sync_val_compare_and_swap(&v_, expval, newval);
308 return (*oldval == expval);
328 static bool compare_swap(value_type * val, value_type expval, value_type newval, value_type * oldval){
331 return __sync_bool_compare_and_swap(val, expval, newval);
332 *oldval = __sync_val_compare_and_swap(val, expval, newval);
333 return (*oldval == expval);
340 value_type operator =(
const __Myt & c)
volatile{
return (v_ = c.
load());}
341 value_type operator =(value_type c)
volatile{
return (v_ = c);}
342 operator value_type()
const volatile{
return load();}
343 value_type operator ++()
volatile{
return add_fetch(1);}
344 value_type operator --()
volatile{
return sub_fetch(1);}
345 value_type operator ++(
int)
volatile{
return fetch_add(1);}
346 value_type operator --(
int)
volatile{
return fetch_sub(1);}
347 value_type operator +=(value_type c)
volatile{
return add_fetch(c);}
348 value_type operator -=(value_type c)
volatile{
return sub_fetch(c);}
349 value_type operator |=(value_type c)
volatile{
return or_fetch(c);}
350 value_type operator &=(value_type c)
volatile{
return and_fetch(c);}
351 value_type operator ^=(value_type c)
volatile{
return xor_fetch(c);}
static value_type fetch_and(value_type *v, value_type c)
Get value and then AND atomically.
Definition: atomic_sync.hh:211
static value_type fetch_xor(value_type *v, value_type c)
Get value and then XOR atomically.
Definition: atomic_sync.hh:247
static value_type swap(value_type *v, value_type c)
Get value and then set atomically.
Definition: atomic_sync.hh:283
static value_type or_fetch(value_type *v, value_type c)
OR and then get value atomically.
Definition: atomic_sync.hh:193
value_type and_fetch(value_type c) volatile
AND and then get value atomically.
Definition: atomic_sync.hh:221
static value_type load(const value_type *v)
Get value atomically.
Definition: atomic_sync.hh:69
static value_type add_fetch(value_type *v, value_type c)
ADD and then get value atomically.
Definition: atomic_sync.hh:121
static bool compare_swap(value_type *val, value_type expval, value_type newval, value_type *oldval)
Compare and set atomically.
Definition: atomic_sync.hh:328
value_type swap(value_type c) volatile
Get value and then set atomically.
Definition: atomic_sync.hh:275
CAtomicSync(const __Myt &c)
Initialize from another CAtomicSync.
Definition: atomic_sync.hh:56
value_type or_fetch(value_type c) volatile
OR and then get value atomically.
Definition: atomic_sync.hh:185
value_type load() const volatile
Get value atomically.
Definition: atomic_sync.hh:61
CAtomicSync(value_type c=value_type())
Initialize with a value.
Definition: atomic_sync.hh:51
static value_type xor_fetch(value_type *v, value_type c)
XOR and then get value atomically.
Definition: atomic_sync.hh:265
static value_type fetch_sub(value_type *v, value_type c)
Get value and then SUBTRACT atomically.
Definition: atomic_sync.hh:139
value_type fetch_sub(value_type c) volatile
Get value and then SUBTRACT atomically.
Definition: atomic_sync.hh:131
value_type xor_fetch(value_type c) volatile
XOR and then get value atomically.
Definition: atomic_sync.hh:257
value_type fetch_xor(value_type c) volatile
Get value and then XOR atomically.
Definition: atomic_sync.hh:239
value_type fetch_or(value_type c) volatile
Get value and then OR atomically.
Definition: atomic_sync.hh:167
static value_type fetch_or(value_type *v, value_type c)
Get value and then OR atomically.
Definition: atomic_sync.hh:175
static value_type and_fetch(value_type *v, value_type c)
AND and then get value atomically.
Definition: atomic_sync.hh:229
void store(value_type c) volatile
Set value atomically.
Definition: atomic_sync.hh:78
static void store(value_type *v, value_type c)
Set value atomically.
Definition: atomic_sync.hh:85
static value_type sub_fetch(value_type *v, value_type c)
SUBTRACT and then get value atomically.
Definition: atomic_sync.hh:157
bool compare_swap(value_type expval, value_type newval, value_type *oldval=NULL) volatile
Compare and set atomically.
Definition: atomic_sync.hh:304
GCC __sync_XXX based atomic operations for integral types.
Definition: atomic_sync.hh:41
static value_type fetch_add(value_type *v, value_type c)
Get value and then ADD atomically.
Definition: atomic_sync.hh:103
value_type fetch_and(value_type c) volatile
Get value and then AND atomically.
Definition: atomic_sync.hh:203
value_type add_fetch(value_type c) volatile
ADD and then get value atomically.
Definition: atomic_sync.hh:113
value_type fetch_add(value_type c) volatile
Get value and then ADD atomically.
Definition: atomic_sync.hh:95
value_type sub_fetch(value_type c) volatile
SUBTRACT and then get value atomically.
Definition: atomic_sync.hh:149