1 //===-- sanitizer_atomic.h --------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of ThreadSanitizer/AddressSanitizer runtime.
11 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_ATOMIC_H
14 #define SANITIZER_ATOMIC_H
16 #include "sanitizer_internal_defs.h"
18 namespace __sanitizer
{
21 memory_order_relaxed
= 1 << 0,
22 memory_order_consume
= 1 << 1,
23 memory_order_acquire
= 1 << 2,
24 memory_order_release
= 1 << 3,
25 memory_order_acq_rel
= 1 << 4,
26 memory_order_seq_cst
= 1 << 5
29 struct atomic_uint8_t
{
31 volatile Type val_dont_use
;
34 struct atomic_uint16_t
{
36 volatile Type val_dont_use
;
39 struct atomic_sint32_t
{
41 volatile Type val_dont_use
;
44 struct atomic_uint32_t
{
46 volatile Type val_dont_use
;
49 struct atomic_uint64_t
{
51 // On 32-bit platforms u64 is not necessary aligned on 8 bytes.
52 volatile ALIGNED(8) Type val_dont_use
;
55 struct atomic_uintptr_t
{
57 volatile Type val_dont_use
;
60 } // namespace __sanitizer
62 #if defined(__clang__) || defined(__GNUC__)
63 # include "sanitizer_atomic_clang.h"
64 #elif defined(_MSC_VER)
65 # include "sanitizer_atomic_msvc.h"
67 # error "Unsupported compiler"
70 namespace __sanitizer
{
72 // Clutter-reducing helpers.
75 inline typename
T::Type
atomic_load_relaxed(const volatile T
*a
) {
76 return atomic_load(a
, memory_order_relaxed
);
80 inline void atomic_store_relaxed(volatile T
*a
, typename
T::Type v
) {
81 atomic_store(a
, v
, memory_order_relaxed
);
84 } // namespace __sanitizer
86 #endif // SANITIZER_ATOMIC_H