169 static_assert(std::is_trivially_copyable_v<T>);
170 static_assert(
sizeof(T) == 1 ||
sizeof(T) == 2 ||
sizeof(T) == 4 ||
sizeof(T) == 8);
178 : m_word{
Detail::WordCreate(sizeof(T))} {}
333 template <
class Delta>
336 return Fetch(
static_cast<std::int64_t
>(
static_cast<std::ptrdiff_t
>(delta)) *
static_cast<std::int64_t
>(
sizeof(std::remove_pointer_t<T>)), order, 0);
338 return Fetch(
static_cast<std::int64_t
>(delta), order, 0);
348 template <
class Delta>
351 return Fetch(
static_cast<std::int64_t
>(
static_cast<std::ptrdiff_t
>(delta)) *
static_cast<std::int64_t
>(
sizeof(std::remove_pointer_t<T>)), order, 1);
353 return Fetch(
static_cast<std::int64_t
>(delta), order, 1);
363 return Fetch(
static_cast<std::int64_t
>(bits), order, 2);
373 return Fetch(
static_cast<std::int64_t
>(bits), order, 3);
383 return Fetch(
static_cast<std::int64_t
>(bits), order, 4);
395 return Extremum(value, order);
405 return Extremum(value, order,
false);
413 return static_cast<T
>(
fetch_add(T{1}) + T{1});
429 return static_cast<T
>(
fetch_sub(T{1}) - T{1});
446 return static_cast<T
>(
fetch_add(delta) + delta);
455 return static_cast<T
>(
fetch_sub(delta) - delta);
464 return static_cast<T
>(
fetch_and(bits) & bits);
473 return static_cast<T
>(
fetch_or(bits) | bits);
482 return static_cast<T
>(
fetch_xor(bits) ^ bits);
489 operator T() const noexcept {
514 T Fetch(std::int64_t delta,
MemoryOrder order,
int op)
noexcept {
527 T Extremum(T value,
MemoryOrder order,
bool maximum =
true) noexcept {
530 const bool replace = maximum ? (current < value) : (value < current);
Atomic word of one, two, four or eight bytes.
Definition atomic.hxx:168
T operator--() noexcept
Pre-decrement.
Definition atomic.hxx:428
bool compare_exchange_weak(T &expected, T desired, MemoryOrder success, MemoryOrder failure) noexcept
Weak compare-exchange.
Definition atomic.hxx:263
~Atomic() noexcept
Destroys the word on Base's heap.
Definition atomic.hxx:197
T fetch_and(T bits, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Bitwise and, returning the previous value.
Definition atomic.hxx:362
void notify_all() noexcept
Wake every waiter.
Definition atomic.hxx:320
T operator++() noexcept
Pre-increment.
Definition atomic.hxx:412
bool compare_exchange_weak(T &expected, T desired, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Weak compare-exchange with one order.
Definition atomic.hxx:274
T exchange(T desired, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Replace the value.
Definition atomic.hxx:249
T operator^=(T bits) noexcept
Xor and return the new value.
Definition atomic.hxx:481
T load(MemoryOrder order=MemoryOrder::SeqCst) const noexcept
Load the value.
Definition atomic.hxx:228
T fetch_or(T bits, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Bitwise or, returning the previous value.
Definition atomic.hxx:372
T fetch_xor(T bits, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Bitwise xor, returning the previous value.
Definition atomic.hxx:382
T fetch_min(T value, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Replace the value with the lesser of it and value.
Definition atomic.hxx:404
T operator+=(T delta) noexcept
Add and return the new value.
Definition atomic.hxx:445
T fetch_max(T value, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Replace the value with the greater of it and value.
Definition atomic.hxx:394
Atomic(T desired)
Value-initialized word.
Definition atomic.hxx:185
void wait(T old, MemoryOrder order=MemoryOrder::SeqCst) const noexcept
Wait while the value is still old.
Definition atomic.hxx:306
void notify_one() noexcept
Wake one waiter.
Definition atomic.hxx:313
Atomic(const Atomic &)=delete
void store(T desired, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Store a value.
Definition atomic.hxx:239
T operator-=(T delta) noexcept
Subtract and return the new value.
Definition atomic.hxx:454
T operator&=(T bits) noexcept
And and return the new value.
Definition atomic.hxx:463
bool compare_exchange_strong(T &expected, T desired, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Strong compare-exchange with one order.
Definition atomic.hxx:297
T fetch_sub(Delta delta, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Subtract and return the previous value.
Definition atomic.hxx:349
T operator++(int) noexcept
Post-increment.
Definition atomic.hxx:420
T fetch_add(Delta delta, MemoryOrder order=MemoryOrder::SeqCst) noexcept
Add and return the previous value.
Definition atomic.hxx:334
bool is_lock_free() const noexcept
Whether Base's word is lock-free.
Definition atomic.hxx:219
Atomic & operator=(Atomic &&)=delete
Atomic()
Zero-initialized value.
Definition atomic.hxx:177
T operator--(int) noexcept
Post-decrement.
Definition atomic.hxx:436
bool compare_exchange_strong(T &expected, T desired, MemoryOrder success, MemoryOrder failure) noexcept
Strong compare-exchange.
Definition atomic.hxx:286
T operator|=(T bits) noexcept
Or and return the new value.
Definition atomic.hxx:472
Atomic & operator=(const Atomic &)=delete
T operator=(T desired) noexcept
Store a value.
Definition atomic.hxx:210
Integral type (bool, char, int, long, …), including cv.
Definition categories.hxx:185
Raw (possibly cv-qualified) pointer type.
Definition categories.hxx:131
void WordLoad(void *word, std::size_t bytes, void *out, MemoryOrder order) noexcept
Load the low bytes of a word.
bool WordCompareExchange(void *word, std::size_t bytes, void *expected, const void *desired, MemoryOrder success, MemoryOrder failure, bool weak) noexcept
Compare-exchange the low bytes.
void * WordCreate(std::size_t bytes)
Allocate a zeroed word on Base's heap.
void WordStore(void *word, std::size_t bytes, const void *value, MemoryOrder order) noexcept
Store bytes into the low part of a word.
void WordExchange(void *word, std::size_t bytes, const void *desired, void *previous, MemoryOrder order) noexcept
Replace the value and return the previous one.
void WordWait(void *word, std::size_t bytes, const void *old, MemoryOrder order) noexcept
Wait while the low bytes still equal old.
void WordNotifyAll(void *word) noexcept
Wake every waiter on word.
bool WordLockFree(void *word) noexcept
Whether Base's word is lock-free.
void WordFetchOp(void *word, std::size_t bytes, std::int64_t delta, void *previous, MemoryOrder order, int op) noexcept
Integer operation on the low bytes.
void WordNotifyOne(void *word) noexcept
Wake one waiter on word.
void WordDestroy(void *word) noexcept
Destroy a word from WordCreate.
Owned values that cross a DLL without the caller's CRT.
MemoryOrder
Ordering for a Atomic operation.
Definition memory_order.hxx:60
@ AcqRel
Acquire plus release.
Definition memory_order.hxx:65
@ Relaxed
No inter-thread ordering.
Definition memory_order.hxx:61
@ Acquire
Acquire.
Definition memory_order.hxx:63
@ Release
Release.
Definition memory_order.hxx:64
@ SeqCst
Sequentially consistent.
Definition memory_order.hxx:66
Root namespace of the StormByte suite.
Octet count. Defined in byte_size.hxx. Forwarded so Type::Numeral can name it.
#define STORMBYTE_PUBLIC
Definition visibility.h:52