Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/atomic/atomic.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 #ifndef BOOST_ATOMIC_ATOMIC_HPP | |
2 #define BOOST_ATOMIC_ATOMIC_HPP | |
3 | |
4 // Copyright (c) 2011 Helge Bahmann | |
5 // Copyright (c) 2013 Tim Blechmann | |
6 // | |
7 // Distributed under the Boost Software License, Version 1.0. | |
8 // See accompanying file LICENSE_1_0.txt or copy at | |
9 // http://www.boost.org/LICENSE_1_0.txt) | |
10 | |
11 #include <cstddef> | |
12 #include <boost/cstdint.hpp> | |
13 | |
14 #include <boost/memory_order.hpp> | |
15 | |
16 #include <boost/atomic/detail/config.hpp> | |
17 #include <boost/atomic/detail/platform.hpp> | |
18 #include <boost/atomic/detail/type-classification.hpp> | |
19 #include <boost/type_traits/is_signed.hpp> | |
20 #if defined(BOOST_MSVC) && BOOST_MSVC < 1400 | |
21 #include <boost/type_traits/is_integral.hpp> | |
22 #include <boost/mpl/and.hpp> | |
23 #endif | |
24 | |
25 #ifdef BOOST_HAS_PRAGMA_ONCE | |
26 #pragma once | |
27 #endif | |
28 | |
29 namespace boost { | |
30 | |
31 #ifndef BOOST_ATOMIC_CHAR_LOCK_FREE | |
32 #define BOOST_ATOMIC_CHAR_LOCK_FREE 0 | |
33 #endif | |
34 | |
35 #ifndef BOOST_ATOMIC_CHAR16_T_LOCK_FREE | |
36 #define BOOST_ATOMIC_CHAR16_T_LOCK_FREE 0 | |
37 #endif | |
38 | |
39 #ifndef BOOST_ATOMIC_CHAR32_T_LOCK_FREE | |
40 #define BOOST_ATOMIC_CHAR32_T_LOCK_FREE 0 | |
41 #endif | |
42 | |
43 #ifndef BOOST_ATOMIC_WCHAR_T_LOCK_FREE | |
44 #define BOOST_ATOMIC_WCHAR_T_LOCK_FREE 0 | |
45 #endif | |
46 | |
47 #ifndef BOOST_ATOMIC_SHORT_LOCK_FREE | |
48 #define BOOST_ATOMIC_SHORT_LOCK_FREE 0 | |
49 #endif | |
50 | |
51 #ifndef BOOST_ATOMIC_INT_LOCK_FREE | |
52 #define BOOST_ATOMIC_INT_LOCK_FREE 0 | |
53 #endif | |
54 | |
55 #ifndef BOOST_ATOMIC_LONG_LOCK_FREE | |
56 #define BOOST_ATOMIC_LONG_LOCK_FREE 0 | |
57 #endif | |
58 | |
59 #ifndef BOOST_ATOMIC_LLONG_LOCK_FREE | |
60 #define BOOST_ATOMIC_LLONG_LOCK_FREE 0 | |
61 #endif | |
62 | |
63 #ifndef BOOST_ATOMIC_INT128_LOCK_FREE | |
64 #define BOOST_ATOMIC_INT128_LOCK_FREE 0 | |
65 #endif | |
66 | |
67 #ifndef BOOST_ATOMIC_POINTER_LOCK_FREE | |
68 #define BOOST_ATOMIC_POINTER_LOCK_FREE 0 | |
69 #endif | |
70 | |
71 #define BOOST_ATOMIC_ADDRESS_LOCK_FREE BOOST_ATOMIC_POINTER_LOCK_FREE | |
72 | |
73 #ifndef BOOST_ATOMIC_BOOL_LOCK_FREE | |
74 #define BOOST_ATOMIC_BOOL_LOCK_FREE 0 | |
75 #endif | |
76 | |
77 #ifndef BOOST_ATOMIC_THREAD_FENCE | |
78 #define BOOST_ATOMIC_THREAD_FENCE 0 | |
79 inline void atomic_thread_fence(memory_order) | |
80 { | |
81 } | |
82 #endif | |
83 | |
84 #ifndef BOOST_ATOMIC_SIGNAL_FENCE | |
85 #define BOOST_ATOMIC_SIGNAL_FENCE 0 | |
86 inline void atomic_signal_fence(memory_order order) | |
87 { | |
88 atomic_thread_fence(order); | |
89 } | |
90 #endif | |
91 | |
92 template<typename T> | |
93 class atomic : | |
94 public atomics::detail::base_atomic< | |
95 T, | |
96 typename atomics::detail::classify<T>::type, | |
97 atomics::detail::storage_size_of<T>::value, | |
98 #if !defined(BOOST_MSVC) || BOOST_MSVC >= 1400 | |
99 boost::is_signed<T>::value | |
100 #else | |
101 // MSVC 2003 has problems instantiating is_signed on non-integral types | |
102 mpl::and_< boost::is_integral<T>, boost::is_signed<T> >::value | |
103 #endif | |
104 > | |
105 { | |
106 private: | |
107 typedef T value_type; | |
108 typedef atomics::detail::base_atomic< | |
109 T, | |
110 typename atomics::detail::classify<T>::type, | |
111 atomics::detail::storage_size_of<T>::value, | |
112 #if !defined(BOOST_MSVC) || BOOST_MSVC >= 1400 | |
113 boost::is_signed<T>::value | |
114 #else | |
115 // MSVC 2003 has problems instantiating is_signed on non-itegral types | |
116 mpl::and_< boost::is_integral<T>, boost::is_signed<T> >::value | |
117 #endif | |
118 > super; | |
119 typedef typename super::value_arg_type value_arg_type; | |
120 | |
121 public: | |
122 BOOST_DEFAULTED_FUNCTION(atomic(void), BOOST_NOEXCEPT {}) | |
123 | |
124 // NOTE: The constructor is made explicit because gcc 4.7 complains that | |
125 // operator=(value_arg_type) is considered ambiguous with operator=(atomic const&) | |
126 // in assignment expressions, even though conversion to atomic<> is less preferred | |
127 // than conversion to value_arg_type. | |
128 explicit BOOST_CONSTEXPR atomic(value_arg_type v) BOOST_NOEXCEPT : super(v) {} | |
129 | |
130 value_type operator=(value_arg_type v) volatile BOOST_NOEXCEPT | |
131 { | |
132 this->store(v); | |
133 return v; | |
134 } | |
135 | |
136 operator value_type(void) volatile const BOOST_NOEXCEPT | |
137 { | |
138 return this->load(); | |
139 } | |
140 | |
141 BOOST_DELETED_FUNCTION(atomic(atomic const&)) | |
142 BOOST_DELETED_FUNCTION(atomic& operator=(atomic const&) volatile) | |
143 }; | |
144 | |
145 typedef atomic<char> atomic_char; | |
146 typedef atomic<unsigned char> atomic_uchar; | |
147 typedef atomic<signed char> atomic_schar; | |
148 typedef atomic<uint8_t> atomic_uint8_t; | |
149 typedef atomic<int8_t> atomic_int8_t; | |
150 typedef atomic<unsigned short> atomic_ushort; | |
151 typedef atomic<short> atomic_short; | |
152 typedef atomic<uint16_t> atomic_uint16_t; | |
153 typedef atomic<int16_t> atomic_int16_t; | |
154 typedef atomic<unsigned int> atomic_uint; | |
155 typedef atomic<int> atomic_int; | |
156 typedef atomic<uint32_t> atomic_uint32_t; | |
157 typedef atomic<int32_t> atomic_int32_t; | |
158 typedef atomic<unsigned long> atomic_ulong; | |
159 typedef atomic<long> atomic_long; | |
160 typedef atomic<uint64_t> atomic_uint64_t; | |
161 typedef atomic<int64_t> atomic_int64_t; | |
162 #ifdef BOOST_HAS_LONG_LONG | |
163 typedef atomic<boost::ulong_long_type> atomic_ullong; | |
164 typedef atomic<boost::long_long_type> atomic_llong; | |
165 #endif | |
166 typedef atomic<void*> atomic_address; | |
167 typedef atomic<bool> atomic_bool; | |
168 typedef atomic<wchar_t> atomic_wchar_t; | |
169 #if !defined(BOOST_NO_CXX11_CHAR16_T) | |
170 typedef atomic<char16_t> atomic_char16_t; | |
171 #endif | |
172 #if !defined(BOOST_NO_CXX11_CHAR32_T) | |
173 typedef atomic<char32_t> atomic_char32_t; | |
174 #endif | |
175 | |
176 typedef atomic<int_least8_t> atomic_int_least8_t; | |
177 typedef atomic<uint_least8_t> atomic_uint_least8_t; | |
178 typedef atomic<int_least16_t> atomic_int_least16_t; | |
179 typedef atomic<uint_least16_t> atomic_uint_least16_t; | |
180 typedef atomic<int_least32_t> atomic_int_least32_t; | |
181 typedef atomic<uint_least32_t> atomic_uint_least32_t; | |
182 typedef atomic<int_least64_t> atomic_int_least64_t; | |
183 typedef atomic<uint_least64_t> atomic_uint_least64_t; | |
184 typedef atomic<int_fast8_t> atomic_int_fast8_t; | |
185 typedef atomic<uint_fast8_t> atomic_uint_fast8_t; | |
186 typedef atomic<int_fast16_t> atomic_int_fast16_t; | |
187 typedef atomic<uint_fast16_t> atomic_uint_fast16_t; | |
188 typedef atomic<int_fast32_t> atomic_int_fast32_t; | |
189 typedef atomic<uint_fast32_t> atomic_uint_fast32_t; | |
190 typedef atomic<int_fast64_t> atomic_int_fast64_t; | |
191 typedef atomic<uint_fast64_t> atomic_uint_fast64_t; | |
192 typedef atomic<intmax_t> atomic_intmax_t; | |
193 typedef atomic<uintmax_t> atomic_uintmax_t; | |
194 | |
195 typedef atomic<std::size_t> atomic_size_t; | |
196 typedef atomic<std::ptrdiff_t> atomic_ptrdiff_t; | |
197 | |
198 #if defined(BOOST_HAS_INTPTR_T) | |
199 typedef atomic<intptr_t> atomic_intptr_t; | |
200 typedef atomic<uintptr_t> atomic_uintptr_t; | |
201 #endif | |
202 | |
203 #ifndef BOOST_ATOMIC_FLAG_LOCK_FREE | |
204 #define BOOST_ATOMIC_FLAG_LOCK_FREE 0 | |
205 class atomic_flag | |
206 { | |
207 public: | |
208 BOOST_CONSTEXPR atomic_flag(void) BOOST_NOEXCEPT : v_(false) {} | |
209 | |
210 bool | |
211 test_and_set(memory_order order = memory_order_seq_cst) BOOST_NOEXCEPT | |
212 { | |
213 return v_.exchange(true, order); | |
214 } | |
215 | |
216 void | |
217 clear(memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT | |
218 { | |
219 v_.store(false, order); | |
220 } | |
221 | |
222 BOOST_DELETED_FUNCTION(atomic_flag(atomic_flag const&)) | |
223 BOOST_DELETED_FUNCTION(atomic_flag& operator=(atomic_flag const&)) | |
224 | |
225 private: | |
226 atomic<bool> v_; | |
227 }; | |
228 #endif | |
229 | |
230 } | |
231 | |
232 #endif |