18#if !defined(MONGO_HAVE_CXX11_ATOMICS)
19#error "Cannot use atomic_word_cxx11.h without C++11 <atomic> support"
31#if __cplusplus >= 201103L
35#include <boost/static_assert.hpp>
37#include "mongo/base/disallow_copying.h"
44template <
typename _WordType>
46#if __cplusplus < 201103L
62#if __cplusplus >= 201103L
85 return _value.load(std::memory_order_relaxed);
94 return _value.store(newValue);
105 return _value.exchange(newValue);
118 _value.compare_exchange_strong(expected, newValue);
130 return _value.fetch_add(increment);
141 return _value.fetch_sub(decrement);
167 std::atomic<WordType> _value;
170#if __cplusplus >= 201103L
171#define _ATOMIC_WORD_DECLARE(NAME, WTYPE) \
172 typedef class AtomicWord<WTYPE> NAME; \
174 BOOST_STATIC_ASSERT(sizeof(NAME) == sizeof(WTYPE)); \
175 BOOST_STATIC_ASSERT(std::is_standard_layout<WTYPE>::value); \
178#define _ATOMIC_WORD_DECLARE(NAME, WTYPE) \
179 typedef class AtomicWord<WTYPE> NAME; \
181 BOOST_STATIC_ASSERT(sizeof(NAME) == sizeof(WTYPE)); \
185_ATOMIC_WORD_DECLARE(AtomicUInt32,
unsigned)
186_ATOMIC_WORD_DECLARE(AtomicUInt64,
unsigned long long)
187_ATOMIC_WORD_DECLARE(AtomicInt32,
int)
188_ATOMIC_WORD_DECLARE(AtomicInt64,
long long)
189#undef _ATOMIC_WORD_DECLARE
Implementation of the AtomicWord interface in terms of the C++11 Atomics.
Definition atomic_word_cxx11.h:45
WordType load() const
Gets the current value of this AtomicWord.
Definition atomic_word_cxx11.h:75
WordType swap(WordType newValue)
Atomically swaps the current value of this with "newValue".
Definition atomic_word_cxx11.h:104
WordType fetchAndAdd(WordType increment)
Get the current value of this, add "increment" and store it, atomically.
Definition atomic_word_cxx11.h:129
WordType compareAndSwap(WordType expected, WordType newValue)
Atomic compare and swap.
Definition atomic_word_cxx11.h:116
void store(WordType newValue)
Sets the value of this AtomicWord to "newValue".
Definition atomic_word_cxx11.h:93
WordType subtractAndFetch(WordType decrement)
Get the current value of this, subtract "decrement" and store it, atomically.
Definition atomic_word_cxx11.h:162
AtomicWord(WordType value=WordType(0))
Construct a new word with the given initial value.
Definition atomic_word_cxx11.h:60
WordType fetchAndSubtract(WordType decrement)
Get the current value of this, subtract "decrement" and store it, atomically.
Definition atomic_word_cxx11.h:140
WordType addAndFetch(WordType increment)
Get the current value of this, add "increment" and store it, atomically.
Definition atomic_word_cxx11.h:151
WordType loadRelaxed() const
Gets the current value of this AtomicWord.
Definition atomic_word_cxx11.h:84
_WordType WordType
Underlying value type.
Definition atomic_word_cxx11.h:55
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20