21 #ifndef __TBB_atomic_H 22 #define __TBB_atomic_H 27 #define __TBB_LONG_LONG __int64 29 #define __TBB_LONG_LONG long long 34 #if _MSC_VER && !__INTEL_COMPILER 36 #pragma warning (push) 37 #pragma warning (disable: 4244 4267 4512) 57 #if __TBB_ALIGNAS_PRESENT 58 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) alignas(a) t f; 59 #elif __TBB_ATTRIBUTE_ALIGNED_PRESENT 60 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) t f __attribute__ ((aligned(a))); 61 #elif __TBB_DECLSPEC_ALIGN_PRESENT 62 #define __TBB_DECL_ATOMIC_FIELD(t,f,a) __declspec(align(a)) t f; 64 #error Do not know syntax for forcing alignment. 80 #if _MSC_VER && !_WIN64 82 typedef intptr_t
word;
87 #if __TBB_64BIT_ATOMICS 94 template<
typename value_type,
size_t size>
98 #if __TBB_ATOMIC_CTORS 99 #define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S) \ 100 template<typename value_type> \ 101 struct aligned_storage<value_type,S> { \ 102 __TBB_DECL_ATOMIC_FIELD(value_type,my_value,S) \ 103 aligned_storage() = default ; \ 104 constexpr aligned_storage(value_type value):my_value(value){} \ 108 #define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S) \ 109 template<typename value_type> \ 110 struct aligned_storage<value_type,S> { \ 111 __TBB_DECL_ATOMIC_FIELD(value_type,my_value,S) \ 116 template<
typename value_type>
119 #if __TBB_ATOMIC_CTORS 127 #if __TBB_64BIT_ATOMICS 131 template<
size_t Size, memory_semantics M>
134 #define __TBB_DECL_FENCED_ATOMIC_PRIMITIVES(S,M) \ 135 template<> struct atomic_traits<S,M> { \ 136 typedef atomic_rep<S>::word word; \ 137 inline static word compare_and_swap( volatile void* location, word new_value, word comparand ) { \ 138 return __TBB_machine_cmpswp##S##M(location,new_value,comparand); \ 140 inline static word fetch_and_add( volatile void* location, word addend ) { \ 141 return __TBB_machine_fetchadd##S##M(location,addend); \ 143 inline static word fetch_and_store( volatile void* location, word value ) { \ 144 return __TBB_machine_fetchstore##S##M(location,value); \ 148 #define __TBB_DECL_ATOMIC_PRIMITIVES(S) \ 149 template<memory_semantics M> \ 150 struct atomic_traits<S,M> { \ 151 typedef atomic_rep<S>::word word; \ 152 inline static word compare_and_swap( volatile void* location, word new_value, word comparand ) { \ 153 return __TBB_machine_cmpswp##S(location,new_value,comparand); \ 155 inline static word fetch_and_add( volatile void* location, word addend ) { \ 156 return __TBB_machine_fetchadd##S(location,addend); \ 158 inline static word fetch_and_store( volatile void* location, word value ) { \ 159 return __TBB_machine_fetchstore##S(location,value); \ 163 template<memory_semantics M>
166 #define __TBB_DECL_ATOMIC_LOAD_STORE_PRIMITIVES(M) \ 167 template<> struct atomic_load_store_traits<M> { \ 168 template <typename T> \ 169 inline static T load( const volatile T& location ) { \ 170 return __TBB_load_##M( location ); \ 172 template <typename T> \ 173 inline static void store( volatile T& location, T value ) { \ 174 __TBB_store_##M( location, value ); \ 178 #if __TBB_USE_FENCED_ATOMICS 191 #if __TBB_64BIT_ATOMICS 201 #if __TBB_64BIT_ATOMICS 214 #define __TBB_MINUS_ONE(T) (T(T(0)-T(1))) 226 template<
typename value_type>
235 template<
typename value_t>
237 return converter<value_t>(
value).bits;
239 template<
typename value_t>
241 converter<value_t> u;
246 template<
typename value_t>
249 template<
typename value_t>
258 template<
typename value_t>
273 #if __TBB_ATOMIC_CTORS 277 template<memory_semantics M>
279 return to_value<value_type>(
285 return fetch_and_store<full_fence>(
value);
288 template<memory_semantics M>
290 return to_value<value_type>(
296 return compare_and_swap<full_fence>(
value,comparand);
300 return to_value<value_type>(
305 template<memory_semantics M>
307 return to_value<value_type>(
313 return load<acquire>();
316 template<memory_semantics M>
322 store<release>(
value );
337 template<
typename I,
typename D,
typename StepType>
341 #if __TBB_ATOMIC_CTORS 345 template<memory_semantics M>
351 return fetch_and_add<full_fence>(addend);
354 template<memory_semantics M>
356 return fetch_and_add<M>(1);
363 template<memory_semantics M>
407 struct atomic: internal::atomic_impl<T> {
408 #if __TBB_ATOMIC_CTORS 419 #if __TBB_ATOMIC_CTORS 420 #define __TBB_DECL_ATOMIC(T) \ 421 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 422 atomic() = default; \ 423 constexpr atomic(T arg): internal::atomic_impl_with_arithmetic<T,T,char>(arg) {} \ 425 T operator=( T rhs ) {return store_with_release(rhs);} \ 426 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 429 #define __TBB_DECL_ATOMIC(T) \ 430 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 431 T operator=( T rhs ) {return store_with_release(rhs);} \ 432 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 436 #if __TBB_64BIT_ATOMICS 446 #if _MSC_VER && !_WIN64 447 #if __TBB_ATOMIC_CTORS 453 #define __TBB_DECL_ATOMIC_ALT(T,U) \ 454 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 455 atomic() = default ; \ 456 constexpr atomic(T arg): internal::atomic_impl_with_arithmetic<T,T,char>(arg) {} \ 457 T operator=( U rhs ) {return store_with_release(T(rhs));} \ 458 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 461 #define __TBB_DECL_ATOMIC_ALT(T,U) \ 462 template<> struct atomic<T>: internal::atomic_impl_with_arithmetic<T,T,char> { \ 463 T operator=( U rhs ) {return store_with_release(T(rhs));} \ 464 atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;} \ 467 __TBB_DECL_ATOMIC_ALT(
unsigned,
size_t)
468 __TBB_DECL_ATOMIC_ALT(
int,ptrdiff_t)
480 #if !_MSC_VER || defined(_NATIVE_WCHAR_T_DEFINED) 485 template<
typename T>
struct atomic<T*>: internal::atomic_impl_with_arithmetic<T*,ptrdiff_t,T> {
486 #if __TBB_ATOMIC_CTORS 492 return this->store_with_release(rhs);
495 this->store_with_release(rhs);
return *
this;
503 template<>
struct atomic<
void*>: internal::atomic_impl<void*> {
504 #if __TBB_ATOMIC_CTORS 510 return this->store_with_release(rhs);
513 this->store_with_release(rhs);
return *
this;
520 template <memory_semantics M,
typename T>
523 template <memory_semantics M,
typename T>
526 namespace interface6{
538 template<memory_semantics M,
typename T >
540 T tmp = load<M>(lhs);
541 store<M>(lhs,load<M>(rhs));
554 #if _MSC_VER && !__INTEL_COMPILER 555 #pragma warning (pop) 556 #endif // warnings are restored
Specialization for atomic<void*>, for sake of not allowing arithmetic or operator->.
Base class that provides basic functionality for atomic<T> with fetch_and_add.
Union type used to convert type T to underlying integral type.
T __TBB_load_with_acquire(const volatile T &location)
void * operator=(void *rhs)
static converter< value_t >::bits_type to_bits(value_t value)
atomic_rep< sizeof(value_type)>::word bits_type
Specialization for atomic<T*> with arithmetic and operator->.
ptr_converter(value_t *a_value)
atomic< T > make_atomic(T t)
Make an atomic for use in an initialization (list), as an alternative to zero-initialization or norma...
#define ATOMIC_STORAGE_PARTIAL_SPECIALIZATION(S)
atomic< void * > & operator=(const atomic< void * > &rhs)
value_type operator-=(D value)
value_type operator--(int)
constexpr atomic_impl_with_arithmetic(value_type value)
void swap(atomic< T > &lhs, atomic< T > &rhs)
value_type fetch_and_add(D addend)
value_type compare_and_swap(value_type value, value_type comparand)
value_type fetch_and_decrement()
void store(atomic< T > &a, T value)
constexpr aligned_storage(value_type value)
T load(const atomic< T > &a)
static converter< value_t >::bits_type & to_bits_ref(value_t &value)
memory_semantics
Specifies memory semantics.
#define __TBB_DECL_ATOMIC(T)
#define __TBB_DECL_ATOMIC_PRIMITIVES(S)
value_type fetch_and_increment()
value_type operator++(int)
value_type fetch_and_increment()
#define __TBB_MINUS_ONE(T)
Additive inverse of 1 for type T.
atomic< T > & operator=(const atomic< T > &rhs)
value_type operator+=(D value)
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
Base class that provides basic functionality for atomic<T> without fetch_and_add.
value_type fetch_and_decrement()
constexpr atomic(void *arg)
value_type fetch_and_add(D addend)
value_type fetch_and_store(value_type value)
aligned_storage< T, sizeof(T)> my_storage
Primary template for atomic.
value_type compare_and_swap(value_type value, value_type comparand)
void store(value_type value)
converter(value_type a_value)
constexpr atomic_impl(value_type value)
__TBB_DECL_ATOMIC_LOAD_STORE_PRIMITIVES(full_fence)
atomic< T * > & operator=(const atomic< T * > &rhs)
void store(value_type value)
value_type store_with_release(value_type rhs)
#define __TBB_DECL_FENCED_ATOMIC_PRIMITIVES(S, M)
void __TBB_store_with_release(volatile T &location, V value)
atomic< T > & as_atomic(T &t)
atomic_impl_with_arithmetic()=default
value_type fetch_and_store(value_type value)
static value_t to_value(typename converter< value_t >::bits_type bits)