18 #if !defined(MONGO_HAVE_CXX11_ATOMICS)
19 #error "Cannot use atomic_word_cxx11.h without C++11 <atomic> support"
31 #if __cplusplus >= 201103L
32 #include <type_traits>
35 #include <boost/static_assert.hpp>
37 #include "mongo/base/disallow_copying.h"
44 template <
typename _WordType>
46 #if __cplusplus < 201103L
62 #if __cplusplus >= 201103L
85 return _value.load(std::memory_order_relaxed);
94 return _value.store(newValue);
104 WordType
swap(WordType 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
WordType load() const
Gets the current value of this AtomicWord.
Definition: atomic_word_cxx11.h:75
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
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
WordType compareAndSwap(WordType expected, WordType newValue)
Atomic compare and swap.
Definition: atomic_word_cxx11.h:116
WordType addAndFetch(WordType increment)
Get the current value of this, add "increment" and store it, atomically.
Definition: atomic_word_cxx11.h:151
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 swap(WordType newValue)
Atomically swaps the current value of this with "newValue".
Definition: atomic_word_cxx11.h:104
WordType subtractAndFetch(WordType decrement)
Get the current value of this, subtract "decrement" and store it, atomically.
Definition: atomic_word_cxx11.h:162
WordType fetchAndAdd(WordType increment)
Get the current value of this, add "increment" and store it, atomically.
Definition: atomic_word_cxx11.h:129
Implementation of the AtomicWord interface in terms of the C++11 Atomics.
Definition: atomic_word_cxx11.h:45
void store(WordType newValue)
Sets the value of this AtomicWord to "newValue".
Definition: atomic_word_cxx11.h:93