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