1 //===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
10 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_ATOMIC_H
13 #define SANITIZER_ATOMIC_H
15 #include "sanitizer_internal_defs.h"
17 namespace __sanitizer
{
20 memory_order_relaxed
= 1 << 0,
21 memory_order_consume
= 1 << 1,
22 memory_order_acquire
= 1 << 2,
23 memory_order_release
= 1 << 3,
24 memory_order_acq_rel
= 1 << 4,
25 memory_order_seq_cst
= 1 << 5
28 struct atomic_uint8_t
{
30 volatile Type val_dont_use
;
33 struct atomic_uint16_t
{
35 volatile Type val_dont_use
;
38 struct atomic_sint32_t
{
40 volatile Type val_dont_use
;
43 struct atomic_uint32_t
{
45 volatile Type val_dont_use
;
48 struct atomic_uint64_t
{
50 // On 32-bit platforms u64 is not necessary aligned on 8 bytes.
51 volatile ALIGNED(8) Type val_dont_use
;
54 struct atomic_uintptr_t
{
56 volatile Type val_dont_use
;
59 } // namespace __sanitizer
61 #if defined(__clang__) || defined(__GNUC__)
62 # include "sanitizer_atomic_clang.h"
63 #elif defined(_MSC_VER)
64 # include "sanitizer_atomic_msvc.h"
66 # error "Unsupported compiler"
69 namespace __sanitizer
{
71 // Clutter-reducing helpers.
74 INLINE typename
T::Type
atomic_load_relaxed(const volatile T
*a
) {
75 return atomic_load(a
, memory_order_relaxed
);
79 INLINE
void atomic_store_relaxed(volatile T
*a
, typename
T::Type v
) {
80 atomic_store(a
, v
, memory_order_relaxed
);
83 } // namespace __sanitizer
85 #endif // SANITIZER_ATOMIC_H