Marine Library
1.0
C++ library for Linux Networking Development
|
GCC __sync_XXX
based atomic operations for integral types.
More...
#include <atomic_sync.hh>
Public Types | |
typedef T | value_type |
Public Member Functions | |
CAtomicSync (value_type c=value_type()) | |
Initialize with a value. More... | |
CAtomicSync (const __Myt &c) | |
Initialize from another CAtomicSync. More... | |
value_type | load () const volatile |
Get value atomically. More... | |
void | store (value_type c) volatile |
Set value atomically. More... | |
value_type | fetch_add (value_type c) volatile |
Get value and then ADD atomically. More... | |
value_type | add_fetch (value_type c) volatile |
ADD and then get value atomically. More... | |
value_type | fetch_sub (value_type c) volatile |
Get value and then SUBTRACT atomically. More... | |
value_type | sub_fetch (value_type c) volatile |
SUBTRACT and then get value atomically. More... | |
value_type | fetch_or (value_type c) volatile |
Get value and then OR atomically. More... | |
value_type | or_fetch (value_type c) volatile |
OR and then get value atomically. More... | |
value_type | fetch_and (value_type c) volatile |
Get value and then AND atomically. More... | |
value_type | and_fetch (value_type c) volatile |
AND and then get value atomically. More... | |
value_type | fetch_xor (value_type c) volatile |
Get value and then XOR atomically. More... | |
value_type | xor_fetch (value_type c) volatile |
XOR and then get value atomically. More... | |
value_type | swap (value_type c) volatile |
Get value and then set atomically. More... | |
bool | compare_swap (value_type expval, value_type newval, value_type *oldval=NULL) volatile |
Compare and set atomically. More... | |
Operators | |
Those operators just act as what you've already known, except that they are all atomic operations. | |
value_type | operator= (const __Myt &c) volatile |
value_type | operator= (value_type c) volatile |
operator value_type () const volatile | |
value_type | operator++ () volatile |
value_type | operator-- () volatile |
value_type | operator++ (int) volatile |
value_type | operator-- (int) volatile |
value_type | operator+= (value_type c) volatile |
value_type | operator-= (value_type c) volatile |
value_type | operator|= (value_type c) volatile |
value_type | operator&= (value_type c) volatile |
value_type | operator^= (value_type c) volatile |
Static Public Member Functions | |
static value_type | load (const value_type *v) |
Get value atomically. More... | |
static void | store (value_type *v, value_type c) |
Set value atomically. More... | |
static value_type | fetch_add (value_type *v, value_type c) |
Get value and then ADD atomically. More... | |
static value_type | add_fetch (value_type *v, value_type c) |
ADD and then get value atomically. More... | |
static value_type | fetch_sub (value_type *v, value_type c) |
Get value and then SUBTRACT atomically. More... | |
static value_type | sub_fetch (value_type *v, value_type c) |
SUBTRACT and then get value atomically. More... | |
static value_type | fetch_or (value_type *v, value_type c) |
Get value and then OR atomically. More... | |
static value_type | or_fetch (value_type *v, value_type c) |
OR and then get value atomically. More... | |
static value_type | fetch_and (value_type *v, value_type c) |
Get value and then AND atomically. More... | |
static value_type | and_fetch (value_type *v, value_type c) |
AND and then get value atomically. More... | |
static value_type | fetch_xor (value_type *v, value_type c) |
Get value and then XOR atomically. More... | |
static value_type | xor_fetch (value_type *v, value_type c) |
XOR and then get value atomically. More... | |
static value_type | swap (value_type *v, value_type c) |
Get value and then set atomically. More... | |
static bool | compare_swap (value_type *val, value_type expval, value_type newval, value_type *oldval) |
Compare and set atomically. More... | |
GCC __sync_XXX
based atomic operations for integral types.
A common use of CAtomicSync is a high performance counter shared between threads or processes.
T | An integral type, i.e. int, long, etc. |
|
inlineexplicit |
Initialize with a value.
If no value is provided, default to 0.
c | A value |
|
inline |
Initialize from another CAtomicSync.
c | Another CAtomicSync |
|
inline |
ADD and then get value atomically.
This function performs {*this += c; return *this;}
c | A value |
|
inlinestatic |
ADD and then get value atomically.
This function performs {*v += c; return *v;}
v | Pointer to a value |
c | A value |
|
inline |
AND and then get value atomically.
This function performs {*this &= c; return *this;}
c | A value |
|
inlinestatic |
AND and then get value atomically.
This function performs {*v &= c; return *v;}
v | Pointer to a value |
c | A value |
|
inline |
Compare and set atomically.
This function performs:
[in] | expval | Expected value |
[in] | newval | New value to set |
[out] | oldval | Pointer to a value to receive the old value before setting; Or NULL if not interested |
true
if *this == expval
; otherwise false
true
.
|
inlinestatic |
Compare and set atomically.
This function performs:
[in,out] | val | Pointer to a value |
[in] | expval | Expected value |
[in] | newval | New value to set |
[out] | oldval | Pointer to a value to receive the old value before setting; Or NULL if not interested |
true
if *this == expval
; otherwise false
true
.
|
inline |
Get value and then ADD atomically.
This function performs {T old = *this; *this += c; return old;}
c | A value |
|
inlinestatic |
Get value and then ADD atomically.
This function performs {T old = *v; *v += c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
Get value and then AND atomically.
This function performs {T old = *this; *this &= c; return old;}
c | A value |
|
inlinestatic |
Get value and then AND atomically.
This function performs {T old = *v; *v &= c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
Get value and then OR atomically.
This function performs {T old = *this; *this |= c; return old;}
c | A value |
|
inlinestatic |
Get value and then OR atomically.
This function performs {T old = *v; *v |= c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
Get value and then SUBTRACT atomically.
This function performs {T old = *this; *this -= c; return old;}
c | A value |
|
inlinestatic |
Get value and then SUBTRACT atomically.
This function performs {T old = *v; *v -= c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
Get value and then XOR atomically.
This function performs {T old = *this; *this ^= c; return old;}
c | A value |
|
inlinestatic |
Get value and then XOR atomically.
This function performs {T old = *v; *v ^= c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
Get value atomically.
*this
|
inlinestatic |
Get value atomically.
v | Pointer to a value |
v
, i.e. *v
|
inline |
OR and then get value atomically.
This function performs {*this |= c; return *this;}
c | A value |
|
inlinestatic |
OR and then get value atomically.
This function performs {*v |= c; return *v;}
v | Pointer to a value |
c | A value |
|
inline |
Set value atomically.
This function performs {*this = c}
.
c | A Value |
|
inlinestatic |
Set value atomically.
This function performs {*v = c}
.
v | Pointer to a value |
c | A Value |
|
inline |
SUBTRACT and then get value atomically.
This function performs {*this -= c; return *this;}
c | A value |
|
inlinestatic |
SUBTRACT and then get value atomically.
This function performs {*v -= c; return *v;}
v | Pointer to a value |
c | A value |
|
inline |
Get value and then set atomically.
This function performs {T old = *this; *this = c; return old;}
c | A value |
|
inlinestatic |
Get value and then set atomically.
This function performs {T old = *v; *v = c; return old;}
v | Pointer to a value |
c | A value |
|
inline |
XOR and then get value atomically.
This function performs {*this ^= c; return *this;}
c | A value |
|
inlinestatic |
XOR and then get value atomically.
This function performs {*v ^= c; return *v;}
v | Pointer to a value |
c | A value |