1 //===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // This file is a part of ThreadSanitizer/AddressSanitizer runtime. 9 // 10 //===----------------------------------------------------------------------===// 11 12 #ifndef SANITIZER_ATOMIC_H 13 #define SANITIZER_ATOMIC_H 14 15 #include "sanitizer_internal_defs.h" 16 17 namespace __sanitizer { 18 19 enum memory_order { 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 26 }; 27 28 struct atomic_uint8_t { 29 typedef u8 Type; 30 volatile Type val_dont_use; 31 }; 32 33 struct atomic_uint16_t { 34 typedef u16 Type; 35 volatile Type val_dont_use; 36 }; 37 38 struct atomic_uint32_t { 39 typedef u32 Type; 40 volatile Type val_dont_use; 41 }; 42 43 struct atomic_uint64_t { 44 typedef u64 Type; 45 // On 32-bit platforms u64 is not necessary aligned on 8 bytes. 46 volatile ALIGNED(8) Type val_dont_use; 47 }; 48 49 struct atomic_uintptr_t { 50 typedef uptr Type; 51 volatile Type val_dont_use; 52 }; 53 54 } // namespace __sanitizer 55 56 #if defined(__clang__) || defined(__GNUC__) 57 # include "sanitizer_atomic_clang.h" 58 #elif defined(_MSC_VER) 59 # include "sanitizer_atomic_msvc.h" 60 #else 61 # error "Unsupported compiler" 62 #endif 63 64 namespace __sanitizer { 65 66 // Clutter-reducing helpers. 67 68 template<typename T> 69 INLINE typename T::Type atomic_load_relaxed(const volatile T *a) { 70 return atomic_load(a, memory_order_relaxed); 71 } 72 73 template<typename T> 74 INLINE void atomic_store_relaxed(volatile T *a, typename T::Type v) { 75 atomic_store(a, v, memory_order_relaxed); 76 } 77 78 } // namespace __sanitizer 79 80 #endif // SANITIZER_ATOMIC_H 81