gcc-cas.hpp
Go to the documentation of this file.
1 // Copyright (c) 2011 Helge Bahmann
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 // Use the gnu builtin __sync_val_compare_and_swap to build
8 // atomic operations for 32 bit and smaller.
9 
10 #ifndef BOOST_DETAIL_ATOMIC_GENERIC_CAS_HPP
11 #define BOOST_DETAIL_ATOMIC_GENERIC_CAS_HPP
12 
13 #define BOOST_ATOMIC_CHAR_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 (sizeof(long) <= 4 ? 2 : 0)
17 #define BOOST_ATOMIC_LLONG_LOCK_FREE (sizeof(long long) <= 4 ? 2 : 0)
18 #define BOOST_ATOMIC_ADDRESS_LOCK_FREE (sizeof(void *) <= 4 ? 2 : 0)
19 #define BOOST_ATOMIC_BOOL_LOCK_FREE 2
20 
21 namespace boost {
22 
23 #define BOOST_ATOMIC_THREAD_FENCE 2
24 inline void
26 {
27  switch(order) {
29  break;
35  __sync_synchronize();
36  break;
37  }
38 }
39 
40 namespace detail {
41 namespace atomic {
42 
43 static inline void
45 {
46  /* empty, as compare_and_swap is synchronizing already */
47 }
48 
49 static inline void
51 {
52  /* empty, as compare_and_swap is synchronizing already */
53 }
54 
55 static inline void
57 {
58  switch(order) {
62  break;
66  __sync_synchronize();
67  break;
68  }
69 }
70 
71 static inline void
73 {
74  if (order == memory_order_seq_cst)
75  __sync_synchronize();
76 }
77 
78 static inline void
80 {
81  switch(order) {
84  break;
89  __sync_synchronize();
90  break;
91  }
92 }
93 
94 template<typename T>
95 bool
96 platform_cmpxchg32_strong(T & expected, T desired, volatile T * ptr)
97 {
98  T found = __sync_val_compare_and_swap(ptr, expected, desired);
99  bool success = (found == expected);
100  expected = found;
101  return success;
102 }
103 
104 }
105 }
106 }
107 
109 
110 #endif
static void platform_fence_before_store(memory_order order)
Definition: gcc-armv6+.hpp:128
Definition: base.hpp:116
static void platform_fence_after_load(memory_order order)
Definition: gcc-armv6+.hpp:141
static void atomic_thread_fence(memory_order order)
Definition: gcc-armv6+.hpp:179
static void platform_fence_after_store(memory_order order)
Definition: gcc-armv6+.hpp:134
bool platform_cmpxchg32_strong(T &expected, T desired, volatile T *ptr)
Definition: gcc-cas.hpp:96
static void platform_fence_after(memory_order order)
Definition: gcc-armv6+.hpp:116
static void platform_fence_before(memory_order order)
Definition: gcc-armv6+.hpp:103


rosatomic
Author(s): Josh Faust
autogenerated on Mon Jun 10 2019 14:44:41