1 #ifndef BOOST_DETAIL_ATOMIC_GCC_X86_HPP 2 #define BOOST_DETAIL_ATOMIC_GCC_X86_HPP 10 #define BOOST_ATOMIC_CHAR_LOCK_FREE 2 11 #define BOOST_ATOMIC_CHAR16_T_LOCK_FREE 2 12 #define BOOST_ATOMIC_CHAR32_T_LOCK_FREE 2 13 #define BOOST_ATOMIC_WCHAR_T_LOCK_FREE 2 14 #define BOOST_ATOMIC_SHORT_LOCK_FREE 2 15 #define BOOST_ATOMIC_INT_LOCK_FREE 2 16 #define BOOST_ATOMIC_LONG_LOCK_FREE 2 18 #if defined(__x86_64__) 19 #define BOOST_ATOMIC_LLONG_LOCK_FREE 2 21 #define BOOST_ATOMIC_LLONG_LOCK_FREE 1 24 #define BOOST_ATOMIC_ADDRESS_LOCK_FREE 2 25 #define BOOST_ATOMIC_BOOL_LOCK_FREE 2 29 #if defined(__x86_64__) 30 # define BOOST_ATOMIC_X86_FENCE_INSTR "mfence\n" 32 # define BOOST_ATOMIC_X86_FENCE_INSTR "lock ; addl $0, (%%esp)\n" 35 #define BOOST_ATOMIC_THREAD_FENCE 2 43 __asm__ __volatile__ (
"" :::
"memory");
46 __asm__ __volatile__ (
"" :::
"memory");
49 __asm__ __volatile__ (
"" :::
"memory");
60 #define BOOST_ATOMIC_SIGNAL_FENCE 2 64 __asm__ __volatile__ (
"" :::
"memory");
80 __asm__ __volatile__ (
"" :::
"memory");
84 __asm__ __volatile__ (
"" :::
"memory");
99 __asm__ __volatile__ (
"" :::
"memory");
106 __asm__ __volatile__ (
"" :::
"memory");
122 __asm__ __volatile__ (
"" :::
"memory");
133 template<
typename T,
bool Sign>
147 const_cast<volatile value_type &
>(
v_) = v;
156 value_type v =
const_cast<const volatile value_type &
>(
v_);
166 "lock ; xaddb %0, %1" 167 :
"+q" (v),
"+m" (
v_)
176 return fetch_add(-v, order);
185 :
"+q" (v),
"+m" (
v_)
193 value_type & expected,
198 value_type previous = expected;
201 "lock ; cmpxchgb %2, %1" 202 :
"+a" (previous),
"+m" (
v_)
205 bool success = (previous == expected);
216 value_type & expected,
261 template<
typename T,
bool Sign>
275 const_cast<volatile value_type &
>(
v_) = v;
284 value_type v =
const_cast<const volatile value_type &
>(
v_);
294 "lock ; xaddw %0, %1" 295 :
"+q" (v),
"+m" (
v_)
304 return fetch_add(-v, order);
313 :
"+q" (v),
"+m" (
v_)
321 value_type & expected,
326 value_type previous = expected;
329 "lock ; cmpxchgw %2, %1" 330 :
"+a" (previous),
"+m" (
v_)
333 bool success = (previous == expected);
344 value_type & expected,
389 template<
typename T,
bool Sign>
403 const_cast<volatile value_type &
>(
v_) = v;
412 value_type v =
const_cast<const volatile value_type &
>(
v_);
422 "lock ; xaddl %0, %1" 423 :
"+r" (v),
"+m" (
v_)
432 return fetch_add(-v, order);
441 :
"+r" (v),
"+m" (
v_)
449 value_type & expected,
454 value_type previous = expected;
457 "lock ; cmpxchgl %2, %1" 458 :
"+a" (previous),
"+m" (
v_)
461 bool success = (previous == expected);
472 value_type & expected,
517 #if defined(__x86_64__) 518 template<
typename T,
bool Sign>
532 const_cast<volatile value_type &
>(
v_) = v;
541 value_type v =
const_cast<const volatile value_type &
>(
v_);
551 "lock ; xaddq %0, %1" 552 :
"+r" (v),
"+m" (
v_)
561 return fetch_add(-v, order);
570 :
"+r" (v),
"+m" (
v_)
578 value_type & expected,
583 value_type previous = expected;
586 "lock ; cmpxchgq %2, %1" 587 :
"+a" (previous),
"+m" (
v_)
590 bool success = (previous == expected);
601 value_type & expected,
650 #if !defined(__x86_64__) 665 const_cast<volatile value_type &
>(
v_) = v;
673 value_type v =
const_cast<const volatile value_type &
>(
v_);
683 :
"+r" (v),
"+m" (
v_)
693 value_type previous = expected;
696 "lock ; cmpxchgl %2, %1" 697 :
"+a" (previous),
"+m" (
v_)
700 bool success = (previous == expected);
729 template<
typename T,
bool Sign>
743 const_cast<volatile value_type &
>(
v_) = v;
752 value_type v =
const_cast<const volatile value_type &
>(
v_);
763 :
"+r" (v),
"+m" (
v_)
771 value_type & expected,
776 value_type previous = expected;
779 "lock ; cmpxchgl %2, %1" 780 :
"+a" (previous),
"+m" (
v_)
783 bool success = (previous == expected);
794 value_type & expected,
808 "lock ; xaddl %0, %1" 809 :
"+r" (v),
"+m" (v_)
812 return reinterpret_cast<value_type
>(v);
818 return fetch_add(-v, order);
849 const_cast<volatile value_type &
>(
v_) = v;
857 value_type v =
const_cast<const volatile value_type &
>(
v_);
867 :
"+r" (v),
"+m" (
v_)
877 value_type previous = expected;
880 "lock ; cmpxchgq %2, %1" 881 :
"+a" (previous),
"+m" (
v_)
884 bool success = (previous == expected);
913 template<
typename T,
bool Sign>
927 const_cast<volatile value_type &
>(
v_) = v;
936 value_type v =
const_cast<const volatile value_type &
>(
v_);
947 :
"+r" (v),
"+m" (
v_)
955 value_type & expected,
960 value_type previous = expected;
963 "lock ; cmpxchgq %2, %1" 964 :
"+a" (previous),
"+m" (
v_)
967 bool success = (previous == expected);
978 value_type & expected,
992 "lock ; xaddq %0, %1" 993 :
"+r" (v),
"+m" (v_)
996 return reinterpret_cast<value_type
>(v);
1002 return fetch_add(-v, order);
1020 template<
typename T,
bool Sign>
1028 memcpy(&
v_, &v,
sizeof(value_type));
1037 memcpy(&tmp, &v,
sizeof(value_type));
1039 const_cast<volatile storage_type &
>(
v_) = tmp;
1048 storage_type tmp =
const_cast<volatile storage_type &
>(
v_);
1051 memcpy(&v, &tmp,
sizeof(value_type));
1059 memcpy(&tmp, &v,
sizeof(value_type));
1063 :
"+q" (tmp),
"+m" (
v_)
1066 memcpy(&v, &tmp,
sizeof(value_type));
1072 value_type & expected,
1077 storage_type expected_s, desired_s;
1078 memcpy(&expected_s, &expected,
sizeof(value_type));
1079 memcpy(&desired_s, &desired,
sizeof(value_type));
1080 storage_type previous_s = expected_s;
1083 "lock ; cmpxchgb %2, %1" 1084 :
"+a" (previous_s),
"+m" (
v_)
1087 bool success = (previous_s == expected_s);
1092 memcpy(&expected, &previous_s,
sizeof(value_type));
1098 value_type & expected,
1119 template<
typename T,
bool Sign>
1127 memcpy(&
v_, &v,
sizeof(value_type));
1136 memcpy(&tmp, &v,
sizeof(value_type));
1138 const_cast<volatile storage_type &
>(
v_) = tmp;
1147 storage_type tmp =
const_cast<volatile storage_type &
>(
v_);
1150 memcpy(&v, &tmp,
sizeof(value_type));
1158 memcpy(&tmp, &v,
sizeof(value_type));
1162 :
"+q" (tmp),
"+m" (
v_)
1165 memcpy(&v, &tmp,
sizeof(value_type));
1171 value_type & expected,
1176 storage_type expected_s, desired_s;
1177 memcpy(&expected_s, &expected,
sizeof(value_type));
1178 memcpy(&desired_s, &desired,
sizeof(value_type));
1179 storage_type previous_s = expected_s;
1182 "lock ; cmpxchgw %2, %1" 1183 :
"+a" (previous_s),
"+m" (
v_)
1186 bool success = (previous_s == expected_s);
1191 memcpy(&expected, &previous_s,
sizeof(value_type));
1197 value_type & expected,
1218 template<
typename T,
bool Sign>
1226 memcpy(&
v_, &v,
sizeof(value_type));
1235 memcpy(&tmp, &v,
sizeof(value_type));
1237 const_cast<volatile storage_type &
>(
v_) = tmp;
1246 storage_type tmp =
const_cast<volatile storage_type &
>(
v_);
1249 memcpy(&v, &tmp,
sizeof(value_type));
1257 memcpy(&tmp, &v,
sizeof(value_type));
1261 :
"+q" (tmp),
"+m" (
v_)
1264 memcpy(&v, &tmp,
sizeof(value_type));
1270 value_type & expected,
1275 storage_type expected_s, desired_s;
1276 memcpy(&expected_s, &expected,
sizeof(value_type));
1277 memcpy(&desired_s, &desired,
sizeof(value_type));
1278 storage_type previous_s = expected_s;
1281 "lock ; cmpxchgl %2, %1" 1282 :
"+a" (previous_s),
"+m" (
v_)
1285 bool success = (previous_s == expected_s);
1290 memcpy(&expected, &previous_s,
sizeof(value_type));
1296 value_type & expected,
1317 #if defined(__x86_64__) 1318 template<
typename T,
bool Sign>
1326 memcpy(&
v_, &v,
sizeof(value_type));
1335 memcpy(&tmp, &v,
sizeof(value_type));
1337 const_cast<volatile storage_type &
>(
v_) = tmp;
1346 storage_type tmp =
const_cast<volatile storage_type &
>(
v_);
1349 memcpy(&v, &tmp,
sizeof(value_type));
1357 memcpy(&tmp, &v,
sizeof(value_type));
1361 :
"+q" (tmp),
"+m" (
v_)
1364 memcpy(&v, &tmp,
sizeof(value_type));
1370 value_type & expected,
1375 storage_type expected_s, desired_s;
1376 memcpy(&expected_s, &expected,
sizeof(value_type));
1377 memcpy(&desired_s, &desired,
sizeof(value_type));
1378 storage_type previous_s = expected_s;
1381 "lock ; cmpxchgq %2, %1" 1382 :
"+a" (previous_s),
"+m" (
v_)
1385 bool success = (previous_s == expected_s);
1390 memcpy(&expected, &previous_s,
sizeof(value_type));
1396 value_type & expected,
1418 #if defined(__i686__) 1420 template<
typename T>
1422 platform_cmpxchg64_strong(T & expected, T desired,
volatile T * ptr)
1440 __asm__ __volatile__ (
1443 "lock; cmpxchg8b 0(%4)\n" 1445 :
"=A" (prev),
"=m" (scratch)
1446 :
"D" ((
int)desired),
"c" ((
int)(desired >> 32)),
"S" (ptr),
"0" (prev)
1448 bool success = (prev == expected);
1460 #if defined(__i686__) #define BOOST_ATOMIC_X86_FENCE_INSTR
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
bool compare_exchange_strong(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
value_type fetch_xor(value_type v, memory_order order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile
static void atomic_signal_fence(memory_order)
value_type fetch_or(value_type v, memory_order order=memory_order_seq_cst) volatile
static void platform_fence_after_load(memory_order order)
value_type fetch_or(value_type v, memory_order order=memory_order_seq_cst) volatile
static void atomic_thread_fence(memory_order order)
base_atomic(value_type v)
bool is_lock_free(void) const volatile
base_atomic(value_type v)
bool is_lock_free(void) const volatile
bool is_lock_free(void) const volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
base_atomic(value_type v)
value_type load(memory_order order=memory_order_seq_cst) const volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
value_type fetch_and(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_and(value_type v, memory_order order=memory_order_seq_cst) volatile
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_add(value_type v, memory_order order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
#define BOOST_ATOMIC_DECLARE_POINTER_OPERATORS
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
base_atomic(value_type v)
value_type load(memory_order=memory_order_seq_cst) volatileconst
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
void store(value_type v, memory_order 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 success_order, memory_order failure_order) volatile
value_type fetch_sub(difference_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_sub(value_type v, memory_order order=memory_order_seq_cst) volatile
static void platform_fence_after(memory_order order)
#define BOOST_ATOMIC_DECLARE_BASE_OPERATORS
base_atomic(value_type v)
base_atomic(value_type v)
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
void store(value_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
ptrdiff_t difference_type
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_or(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_xor(value_type v, memory_order 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 is_lock_free(void) const volatile
bool compare_exchange_weak(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) 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 success_order, memory_order failure_order) volatile
value_type fetch_xor(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
void store(value_type v, memory_order 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
bool compare_exchange_strong(value_type &expected, value_type desired, memory_order success_order, memory_order failure_order) volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
static void platform_fence_before(memory_order order)
value_type fetch_add(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type load(memory_order order=memory_order_seq_cst) const volatile
base_atomic(value_type v)
void store(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_add(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_add(difference_type v, memory_order order=memory_order_seq_cst) volatile
value_type exchange(value_type v, memory_order order=memory_order_seq_cst) volatile
void operator=(const base_atomic &)
value_type fetch_sub(value_type v, memory_order order=memory_order_seq_cst) volatile
value_type fetch_and(value_type v, memory_order order=memory_order_seq_cst) volatile
base_atomic(value_type v)
value_type fetch_sub(value_type v, memory_order order=memory_order_seq_cst) volatile
bool is_lock_free(void) const volatile