17 #ifndef __TBB_atomic_H 18 #define __TBB_atomic_H 23 #define __TBB_LONG_LONG __int64 25 #define __TBB_LONG_LONG long long 30 #if _MSC_VER && !__INTEL_COMPILER 32 #pragma warning (push) 33 #pragma warning (disable: 4244 4267 4512) 53 #if __TBB_ALIGNAS_PRESENT 54 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) alignas(a) t f; 55 #elif __TBB_ATTRIBUTE_ALIGNED_PRESENT 56 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) t f __attribute__ ((aligned(a))); 57 #elif __TBB_DECLSPEC_ALIGN_PRESENT 58 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) __declspec(align(a)) t f; 60 #error Do not know syntax for forcing alignment. 76 #if _MSC_VER && !_WIN64 78 typedef intptr_t
word;
83 #if __TBB_64BIT_ATOMICS 90 template<
typename value_type,
size_t size>
94 #if __TBB_ATOMIC_CTORS 95 #define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S) \ 96 template<typename value_type> \ 97 struct aligned_storage<value_type,S> { \ 98 __TBB_DECL_ATOMIC_FIELD(value_type,my_value,S) \ 99 aligned_storage() = default ; \ 100 constexpr aligned_storage(value_type value):my_value(value){} \ 104 #define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S) \ 105 template<typename value_type> \ 106 struct aligned_storage<value_type,S> { \ 107 __TBB_DECL_ATOMIC_FIELD(value_type,my_value,S) \ 112 template<
typename value_type>
115 #if __TBB_ATOMIC_CTORS 123 #if __TBB_64BIT_ATOMICS 127 template<
size_t Size, memory_semantics M>
130 #define __TBB_DECL_FENCED_ATOMIC_PRIMITIVES(S,M) \ 131 template<> struct atomic_traits<S,M> { \ 132 typedef atomic_rep<S>::word word; \ 133 inline static word compare_and_swap( volatile void* location, word new_value, word comparand ) { \ 134 return __TBB_machine_cmpswp##S##M(location,new_value,comparand); \ 136 inline static word fetch_and_add( volatile void* location, word addend ) { \ 137 return __TBB_machine_fetchadd##S##M(location,addend); \ 139 inline static word fetch_and_store( volatile void* location, word value ) { \ 140 return __TBB_machine_fetchstore##S##M(location,value); \ 144 #define __TBB_DECL_ATOMIC_PRIMITIVES(S) \ 145 template<memory_semantics M> \ 146 struct atomic_traits<S,M> { \ 147 typedef atomic_rep<S>::word word; \ 148 inline static word compare_and_swap( volatile void* location, word new_value, word comparand ) { \ 149 return __TBB_machine_cmpswp##S(location,new_value,comparand); \ 151 inline static word fetch_and_add( volatile void* location, word addend ) { \ 152 return __TBB_machine_fetchadd##S(location,addend); \ 154 inline static word fetch_and_store( volatile void* location, word value ) { \ 155 return __TBB_machine_fetchstore##S(location,value); \ 159 template<memory_semantics M>
162 #define __TBB_DECL_ATOMIC_LOAD_STORE_PRIMITIVES(M) \ 163 template<> struct atomic_load_store_traits<M> { \ 164 template <typename T> \ 165 inline static T load( const volatile T& location ) { \ 166 return __TBB_load_##M( location ); \ 168 template <typename T> \ 169 inline static void store( volatile T& location, T value ) { \ 170 __TBB_store_##M( location, value ); \ 174 #if __TBB_USE_FENCED_ATOMICS 187 #if __TBB_64BIT_ATOMICS 197 #if __TBB_64BIT_ATOMICS 210 #define __TBB_MINUS_ONE(T) (T(T(0)-T(1))) 222 template<
typename value_type>
231 template<
typename value_t>
233 return converter<value_t>(
value).bits;
235 template<
typename value_t>
237 converter<value_t> u;
242 template<
typename value_t>
245 template<
typename value_t>
254 template<
typename value_t>
269 #if __TBB_ATOMIC_CTORS 273 template<memory_semantics M>
275 return to_value<value_type>(
281 return fetch_and_store<full_fence>(
value);
284 template<memory_semantics M>
286 return to_value<value_type>(
292 return compare_and_swap<full_fence>(
value,comparand);
296 return to_value<value_type>(
301 template<memory_semantics M>
303 return to_value<value_type>(
309 return load<acquire>();
312 template<memory_semantics M>
318 store<release>(
value );
333 template<
typename I,
typename D,
typename StepType>
337 #if __TBB_ATOMIC_CTORS 341 template<memory_semantics M>
347 return fetch_and_add<full_fence>(addend);
350 template<memory_semantics M>
352 return fetch_and_add<M>(1);
359 template<memory_semantics M>
403 struct atomic: internal::atomic_impl<T> {
404 #if __TBB_ATOMIC_CTORS 415 #if __TBB_ATOMIC_CTORS 416 #define __TBB_DECL_ATOMIC(T) \ 417 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 418 atomic() = default; \ 419 constexpr atomic(T arg): internal::atomic_impl_with_arithmetic<T,T,char>(arg) {} \ 421 T operator=( T rhs ) {return store_with_release(rhs);} \ 422 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 425 #define __TBB_DECL_ATOMIC(T) \ 426 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 427 T operator=( T rhs ) {return store_with_release(rhs);} \ 428 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 432 #if __TBB_64BIT_ATOMICS 442 #if _MSC_VER && !_WIN64 443 #if __TBB_ATOMIC_CTORS 449 #define __TBB_DECL_ATOMIC_ALT(T,U) \ 450 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 451 atomic() = default ; \ 452 constexpr atomic(T arg): internal::atomic_impl_with_arithmetic<T,T,char>(arg) {} \ 453 T operator=( U rhs ) {return store_with_release(T(rhs));} \ 454 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 457 #define __TBB_DECL_ATOMIC_ALT(T,U) \ 458 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 459 T operator=( U rhs ) {return store_with_release(T(rhs));} \ 460 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 463 __TBB_DECL_ATOMIC_ALT(
unsigned,
size_t)
464 __TBB_DECL_ATOMIC_ALT(
int,ptrdiff_t)
476 #if !_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED) 481 template<
typename T>
struct atomic<T*>: internal::atomic_impl_with_arithmetic<T*,ptrdiff_t,T> {
482 #if __TBB_ATOMIC_CTORS 488 return this->store_with_release(rhs);
491 this->store_with_release(rhs);
return *
this;
499 template<>
struct atomic<
void*>: internal::atomic_impl<void*> {
500 #if __TBB_ATOMIC_CTORS 506 return this->store_with_release(rhs);
509 this->store_with_release(rhs);
return *
this;
516 template <memory_semantics M,
typename T>
519 template <memory_semantics M,
typename T>
522 namespace interface6{
534 template<memory_semantics M,
typename T >
536 T tmp = load<M>(lhs);
537 store<M>(lhs,load<M>(rhs));
550 #if _MSC_VER && !__INTEL_COMPILER 551 #pragma warning (pop) 552 #endif // warnings are restored atomic< T > & operator=(const atomic< T > &rhs)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
atomic_rep< sizeof(value_type)>::word bits_type
void store(value_type value)
constexpr atomic(void *arg)
Specialization for atomic<T*> with arithmetic and operator->.
ptr_converter(value_t *a_value)
value_type fetch_and_store(value_type value)
constexpr atomic_impl(value_type value)
static value_t to_value(typename converter< value_t >::bits_type bits)
void __TBB_store_with_release(volatile T &location, V value)
#define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S)
Primary template for atomic.
atomic_impl_with_arithmetic()=default
void store(value_type value)
atomic< T > make_atomic(T t)
Make an atomic for use in an initialization (list), as an alternative to zero-initialization or norma...
value_type fetch_and_store(value_type value)
Specialization for atomic<void*>, for sake of not allowing arithmetic or operator->.
#define __TBB_DECL_ATOMIC(T)
value_type operator++(int)
#define __TBB_DECL_ATOMIC_PRIMITIVES(S)
converter(value_type a_value)
constexpr atomic_impl_with_arithmetic(value_type value)
value_type compare_and_swap(value_type value, value_type comparand)
Union type used to convert type T to underlying integral type.
aligned_storage< T, sizeof(T)> my_storage
value_type fetch_and_decrement()
void * operator=(void *rhs)
void swap(atomic< T > &lhs, atomic< T > &rhs)
#define __TBB_MINUS_ONE(T)
Additive inverse of 1 for type T.
value_type fetch_and_add(D addend)
static converter< value_t >::bits_type to_bits(value_t value)
Base class that provides basic functionality for atomic<T> without fetch_and_add.
value_type store_with_release(value_type rhs)
atomic< T > & as_atomic(T &t)
atomic< T * > & operator=(const atomic< T * > &rhs)
static converter< value_t >::bits_type & to_bits_ref(value_t &value)
__TBB_DECL_ATOMIC_LOAD_STORE_PRIMITIVES(full_fence)
T load(const atomic< T > &a)
value_type operator-=(D value)
value_type operator--(int)
value_type fetch_and_increment()
Base class that provides basic functionality for atomic<T> with fetch_and_add.
value_type fetch_and_increment()
value_type operator+=(D value)
value_type fetch_and_decrement()
atomic< void * > & operator=(const atomic< void * > &rhs)
value_type fetch_and_add(D addend)
#define __TBB_DECL_FENCED_ATOMIC_PRIMITIVES(S, M)
T __TBB_load_with_acquire(const volatile T &location)
void store(atomic< T > &a, T value)
constexpr aligned_storage(value_type value)
value_type compare_and_swap(value_type value, value_type comparand)
memory_semantics
Specifies memory semantics.