1 //===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_ATOMIC_H
15 #define SANITIZER_ATOMIC_H
17 #include "sanitizer_internal_defs.h"
19 namespace __sanitizer {
22 memory_order_relaxed = 1 << 0,
23 memory_order_consume = 1 << 1,
24 memory_order_acquire = 1 << 2,
25 memory_order_release = 1 << 3,
26 memory_order_acq_rel = 1 << 4,
27 memory_order_seq_cst = 1 << 5
30 struct atomic_uint8_t {
32 volatile Type val_dont_use;
35 struct atomic_uint16_t {
37 volatile Type val_dont_use;
40 struct atomic_sint32_t {
42 volatile Type val_dont_use;
45 struct atomic_uint32_t {
47 volatile Type val_dont_use;
50 struct atomic_uint64_t {
52 // On 32-bit platforms u64 is not necessary aligned on 8 bytes.
53 volatile ALIGNED(8) Type val_dont_use;
56 struct atomic_uintptr_t {
58 volatile Type val_dont_use;
61 } // namespace __sanitizer
63 #if defined(__clang__) || defined(__GNUC__)
64 # include "sanitizer_atomic_clang.h"
65 #elif defined(_MSC_VER)
66 # include "sanitizer_atomic_msvc.h"
68 # error "Unsupported compiler"
71 namespace __sanitizer {
73 // Clutter-reducing helpers.
76 INLINE typename T::Type atomic_load_relaxed(const volatile T *a) {
77 return atomic_load(a, memory_order_relaxed);
81 INLINE void atomic_store_relaxed(volatile T *a, typename T::Type v) {
82 atomic_store(a, v, memory_order_relaxed);
85 } // namespace __sanitizer
87 #endif // SANITIZER_ATOMIC_H