1 #ifndef BOOST_DETAIL_ATOMIC_BASE_HPP 2 #define BOOST_DETAIL_ATOMIC_BASE_HPP 17 #include <boost/smart_ptr/detail/spinlock_pool.hpp> 19 #define BOOST_ATOMIC_DECLARE_BASE_OPERATORS \ 20 operator value_type(void) volatile const \ 22 return load(memory_order_seq_cst); \ 26 operator=(value_type v) volatile \ 28 store(v, memory_order_seq_cst); \ 29 return *const_cast<this_type *>(this); \ 33 compare_exchange_strong( \ 34 value_type & expected, \ 36 memory_order order = memory_order_seq_cst) volatile \ 38 return compare_exchange_strong(expected, desired, order, calculate_failure_order(order)); \ 42 compare_exchange_weak( \ 43 value_type & expected, \ 45 memory_order order = memory_order_seq_cst) volatile \ 47 return compare_exchange_weak(expected, desired, order, calculate_failure_order(order)); \ 51 #define BOOST_ATOMIC_DECLARE_ADDITIVE_OPERATORS \ 53 operator++(int) volatile \ 55 return fetch_add(1); \ 59 operator++(void) volatile \ 61 return fetch_add(1) + 1; \ 65 operator--(int) volatile \ 67 return fetch_sub(1); \ 71 operator--(void) volatile \ 73 return fetch_sub(1) - 1; \ 77 operator+=(difference_type v) volatile \ 79 return fetch_add(v) + v; \ 83 operator-=(difference_type v) volatile \ 85 return fetch_sub(v) - v; \ 88 #define BOOST_ATOMIC_DECLARE_BIT_OPERATORS \ 90 operator&=(difference_type v) volatile \ 92 return fetch_and(v) & v; \ 96 operator|=(difference_type v) volatile \ 98 return fetch_or(v) | v; \ 102 operator^=(difference_type v) volatile \ 104 return fetch_xor(v) ^ v; \ 107 #define BOOST_ATOMIC_DECLARE_POINTER_OPERATORS \ 108 BOOST_ATOMIC_DECLARE_BASE_OPERATORS \ 109 BOOST_ATOMIC_DECLARE_ADDITIVE_OPERATORS \ 111 #define BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS \ 112 BOOST_ATOMIC_DECLARE_BASE_OPERATORS \ 113 BOOST_ATOMIC_DECLARE_ADDITIVE_OPERATORS \ 114 BOOST_ATOMIC_DECLARE_BIT_OPERATORS \ 133 template<
typename T,
typename C ,
unsigned int Size,
bool Sign>
144 memcpy(&
v_, &v, Size);
150 guard_type guard(const_cast<char *>(
v_));
152 memcpy(const_cast<char *>(
v_), &v, Size);
158 guard_type guard(const_cast<const char *>(
v_));
161 memcpy(&v, const_cast<const char *>(
v_), Size);
167 value_type & expected,
172 guard_type guard(const_cast<char *>(
v_));
174 if (memcmp(const_cast<char *>(
v_), &expected, Size) == 0) {
175 memcpy(const_cast<char *>(
v_), &desired, Size);
178 memcpy(&expected, const_cast<char *>(
v_), Size);
185 value_type & expected,
196 guard_type guard(const_cast<char *>(
v_));
199 memcpy(&tmp, const_cast<char *>(
v_), Size);
201 memcpy(const_cast<char *>(
v_), &v, Size);
219 template<
typename T,
unsigned int Size,
bool Sign>
233 guard_type guard(const_cast<value_type *>(&
v_));
241 guard_type guard(const_cast<value_type *>(&
v_));
243 value_type v =
const_cast<const volatile value_type &
>(
v_);
250 guard_type guard(const_cast<value_type *>(&
v_));
262 guard_type guard(const_cast<value_type *>(&
v_));
264 if (
v_ == expected) {
284 guard_type guard(const_cast<value_type *>(&
v_));
294 guard_type guard(const_cast<value_type *>(&
v_));
304 guard_type guard(const_cast<value_type *>(&
v_));
314 guard_type guard(const_cast<value_type *>(&
v_));
324 guard_type guard(const_cast<value_type *>(&
v_));
344 template<
typename T,
unsigned int Size,
bool Sign>
358 guard_type guard(const_cast<value_type *>(&
v_));
365 guard_type guard(const_cast<value_type *>(&
v_));
367 value_type v =
const_cast<const volatile value_type &
>(
v_);
374 guard_type guard(const_cast<value_type *>(&
v_));
386 guard_type guard(const_cast<value_type *>(&
v_));
388 if (
v_ == expected) {
407 guard_type guard(const_cast<value_type *>(&
v_));
416 guard_type guard(const_cast<value_type *>(&
v_));
436 template<
unsigned int Size,
bool Sign>
449 guard_type guard(const_cast<value_type *>(&
v_));
456 guard_type guard(const_cast<value_type *>(&
v_));
458 value_type v =
const_cast<const volatile value_type &
>(
v_);
465 guard_type guard(const_cast<value_type *>(&
v_));
477 guard_type guard(const_cast<value_type *>(&
v_));
479 if (
v_ == expected) {
ptrdiff_t difference_type
value_type exchange(value_type v, memory_order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order, memory_order) volatile
value_type fetch_add(difference_type v, memory_order=memory_order_seq_cst) volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
base_atomic(value_type v)
detail::spinlock_pool< 0 >::scoped_lock guard_type
value_type load(memory_order=memory_order_seq_cst) const volatile
void store(value_type v, memory_order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile
#define BOOST_ATOMIC_DECLARE_POINTER_OPERATORS
value_type fetch_add(difference_type v, memory_order=memory_order_seq_cst) volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order, memory_order) volatile
bool is_lock_free(void) const volatile
value_type fetch_xor(value_type v, memory_order=memory_order_seq_cst) volatile
value_type load(memory_order=memory_order_seq_cst) volatileconst
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order, memory_order) volatile
void store(value_type v, memory_order=memory_order_seq_cst) volatile
detail::spinlock_pool< 0 >::scoped_lock guard_type
static memory_order calculate_failure_order(memory_order order)
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
#define BOOST_ATOMIC_DECLARE_BASE_OPERATORS
base_atomic(const value_type &v)
value_type exchange(value_type v, memory_order=memory_order_seq_cst) volatile
value_type load(memory_order=memory_order_seq_cst) const volatile
void store(value_type v, memory_order=memory_order_seq_cst) volatile
value_type fetch_sub(difference_type v, memory_order=memory_order_seq_cst) volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order, memory_order) volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
detail::spinlock_pool< 0 >::scoped_lock guard_type
base_atomic(value_type v)
value_type fetch_sub(difference_type v, memory_order=memory_order_seq_cst) volatile
value_type exchange(value_type v, memory_order=memory_order_seq_cst) volatile
#define BOOST_ATOMIC_DECLARE_INTEGRAL_OPERATORS
bool is_lock_free(void) const volatile
value_type load(memory_order=memory_order_seq_cst) const volatile
value_type fetch_and(value_type v, memory_order=memory_order_seq_cst) volatile
void operator=(const base_atomic &)
value_type fetch_or(value_type v, memory_order=memory_order_seq_cst) volatile
void store(value_type v, memory_order=memory_order_seq_cst) volatile
detail::spinlock_pool< 0 >::scoped_lock guard_type
value_type exchange(value_type v, memory_order=memory_order_seq_cst) volatile
base_atomic(value_type v)