The atomic routines implement compare-and-swap and atomic variable increment functions.
More...
The atomic routines implement compare-and-swap and atomic variable increment functions.
◆ DEFINE_ATOMIC_INCREMENT_TYPE
#define DEFINE_ATOMIC_INCREMENT_TYPE |
( |
|
suffix, |
|
|
|
typeName |
|
) |
| |
Value: inline typeName atomicIncrement_ ## suffix(typeName *loc, int32_t amount) { typeName newVal; \
bool ok; do { typeName cur = *(loc); newVal = cur + (amount); \
ok = did_compareAndSwap_ ## suffix (loc, cur, newVal); \
} while (ok == false); \
return (newVal); \
}
Implement an atomic increment operator for a native type.
◆ DEFINE_COMPARE_AND_SWAP_TYPE
#define DEFINE_COMPARE_AND_SWAP_TYPE |
( |
|
suffix, |
|
|
|
typeName |
|
) |
| |
Value: inline typeName compareAndSwap_ ## suffix (typeName *loc, typeName oldVal, typeName newVal) { \
typeName result = __sync_val_compare_and_swap(loc, oldVal, newVal); \
return (result); \
}
Implement an inline compare-and-swap routine for a particular type.
◆ DEFINE_DID_COMPARE_AND_SWAP_TYPE
#define DEFINE_DID_COMPARE_AND_SWAP_TYPE |
( |
|
suffix, |
|
|
|
typeName |
|
) |
| |
Value: inline bool did_compareAndSwap_ ## suffix (typeName *loc, typeName oldVal, typeName newVal) { \
bool result = __sync_bool_compare_and_swap(loc, oldVal, newVal); \
return (result); \
}
Implement an inline compare-and-swap routine for a distinct native type, but return a Boolean indicating success.
◆ DEFINE_ATOMIC_INCREMENT_TYPE() [1/2]
DEFINE_ATOMIC_INCREMENT_TYPE |
( |
uint32 |
, |
|
|
uint32_t |
|
|
) |
| |
◆ DEFINE_ATOMIC_INCREMENT_TYPE() [2/2]
DEFINE_ATOMIC_INCREMENT_TYPE |
( |
uint64 |
, |
|
|
uint64_t |
|
|
) |
| |
◆ DEFINE_COMPARE_AND_SWAP_TYPE() [1/3]
DEFINE_COMPARE_AND_SWAP_TYPE |
( |
Pointer |
, |
|
|
void * |
|
|
) |
| |
◆ DEFINE_COMPARE_AND_SWAP_TYPE() [2/3]
DEFINE_COMPARE_AND_SWAP_TYPE |
( |
uint32 |
, |
|
|
uint32_t |
|
|
) |
| |
◆ DEFINE_COMPARE_AND_SWAP_TYPE() [3/3]
DEFINE_COMPARE_AND_SWAP_TYPE |
( |
uint64 |
, |
|
|
uint64_t |
|
|
) |
| |
◆ DEFINE_DID_COMPARE_AND_SWAP_TYPE() [1/3]
DEFINE_DID_COMPARE_AND_SWAP_TYPE |
( |
Pointer |
, |
|
|
void * |
|
|
) |
| |
◆ DEFINE_DID_COMPARE_AND_SWAP_TYPE() [2/3]
DEFINE_DID_COMPARE_AND_SWAP_TYPE |
( |
uint32 |
, |
|
|
uint32_t |
|
|
) |
| |
◆ DEFINE_DID_COMPARE_AND_SWAP_TYPE() [3/3]
DEFINE_DID_COMPARE_AND_SWAP_TYPE |
( |
uint64 |
, |
|
|
uint64_t |
|
|
) |
| |
◆ incrementAtomically()
template<typename NUMTYPE >
NUMTYPE incrementAtomically |
( |
NUMTYPE * |
loc, |
|
|
NUMTYPE |
amount |
|
) |
| |