1//===-- tsan_interface_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 (TSan), a race detector.
11//
12//===----------------------------------------------------------------------===//
13#ifndef TSAN_INTERFACE_ATOMIC_H
14#define TSAN_INTERFACE_ATOMIC_H
15
16#ifndef INTERFACE_ATTRIBUTE
17# define INTERFACE_ATTRIBUTE __attribute__((visibility("default")))
18#endif
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24typedef char     __tsan_atomic8;
25typedef short    __tsan_atomic16;  // NOLINT
26typedef int      __tsan_atomic32;
27typedef long     __tsan_atomic64;  // NOLINT
28
29#if defined(__SIZEOF_INT128__) \
30    || (__clang_major__ * 100 + __clang_minor__ >= 302)
31__extension__ typedef __int128 __tsan_atomic128;
32#define __TSAN_HAS_INT128 1
33#else
34typedef char     __tsan_atomic128;
35#define __TSAN_HAS_INT128 0
36#endif
37
38// Part of ABI, do not change.
39// http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?view=markup
40typedef enum {
41  __tsan_memory_order_relaxed,
42  __tsan_memory_order_consume,
43  __tsan_memory_order_acquire,
44  __tsan_memory_order_release,
45  __tsan_memory_order_acq_rel,
46  __tsan_memory_order_seq_cst
47} __tsan_memory_order;
48
49__tsan_atomic8 __tsan_atomic8_load(const volatile __tsan_atomic8 *a,
50    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
51__tsan_atomic16 __tsan_atomic16_load(const volatile __tsan_atomic16 *a,
52    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
53__tsan_atomic32 __tsan_atomic32_load(const volatile __tsan_atomic32 *a,
54    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
55__tsan_atomic64 __tsan_atomic64_load(const volatile __tsan_atomic64 *a,
56    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
57__tsan_atomic128 __tsan_atomic128_load(const volatile __tsan_atomic128 *a,
58    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
59
60void __tsan_atomic8_store(volatile __tsan_atomic8 *a, __tsan_atomic8 v,
61    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
62void __tsan_atomic16_store(volatile __tsan_atomic16 *a, __tsan_atomic16 v,
63    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
64void __tsan_atomic32_store(volatile __tsan_atomic32 *a, __tsan_atomic32 v,
65    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
66void __tsan_atomic64_store(volatile __tsan_atomic64 *a, __tsan_atomic64 v,
67    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
68void __tsan_atomic128_store(volatile __tsan_atomic128 *a, __tsan_atomic128 v,
69    __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
70
71__tsan_atomic8 __tsan_atomic8_exchange(volatile __tsan_atomic8 *a,
72    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
73__tsan_atomic16 __tsan_atomic16_exchange(volatile __tsan_atomic16 *a,
74    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
75__tsan_atomic32 __tsan_atomic32_exchange(volatile __tsan_atomic32 *a,
76    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
77__tsan_atomic64 __tsan_atomic64_exchange(volatile __tsan_atomic64 *a,
78    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
79__tsan_atomic128 __tsan_atomic128_exchange(volatile __tsan_atomic128 *a,
80    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
81
82__tsan_atomic8 __tsan_atomic8_fetch_add(volatile __tsan_atomic8 *a,
83    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
84__tsan_atomic16 __tsan_atomic16_fetch_add(volatile __tsan_atomic16 *a,
85    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
86__tsan_atomic32 __tsan_atomic32_fetch_add(volatile __tsan_atomic32 *a,
87    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
88__tsan_atomic64 __tsan_atomic64_fetch_add(volatile __tsan_atomic64 *a,
89    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
90__tsan_atomic128 __tsan_atomic128_fetch_add(volatile __tsan_atomic128 *a,
91    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
92
93__tsan_atomic8 __tsan_atomic8_fetch_sub(volatile __tsan_atomic8 *a,
94    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
95__tsan_atomic16 __tsan_atomic16_fetch_sub(volatile __tsan_atomic16 *a,
96    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
97__tsan_atomic32 __tsan_atomic32_fetch_sub(volatile __tsan_atomic32 *a,
98    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
99__tsan_atomic64 __tsan_atomic64_fetch_sub(volatile __tsan_atomic64 *a,
100    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
101__tsan_atomic128 __tsan_atomic128_fetch_sub(volatile __tsan_atomic128 *a,
102    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
103
104__tsan_atomic8 __tsan_atomic8_fetch_and(volatile __tsan_atomic8 *a,
105    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
106__tsan_atomic16 __tsan_atomic16_fetch_and(volatile __tsan_atomic16 *a,
107    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
108__tsan_atomic32 __tsan_atomic32_fetch_and(volatile __tsan_atomic32 *a,
109    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
110__tsan_atomic64 __tsan_atomic64_fetch_and(volatile __tsan_atomic64 *a,
111    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
112__tsan_atomic128 __tsan_atomic128_fetch_and(volatile __tsan_atomic128 *a,
113    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
114
115__tsan_atomic8 __tsan_atomic8_fetch_or(volatile __tsan_atomic8 *a,
116    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
117__tsan_atomic16 __tsan_atomic16_fetch_or(volatile __tsan_atomic16 *a,
118    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
119__tsan_atomic32 __tsan_atomic32_fetch_or(volatile __tsan_atomic32 *a,
120    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
121__tsan_atomic64 __tsan_atomic64_fetch_or(volatile __tsan_atomic64 *a,
122    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
123__tsan_atomic128 __tsan_atomic128_fetch_or(volatile __tsan_atomic128 *a,
124    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
125
126__tsan_atomic8 __tsan_atomic8_fetch_xor(volatile __tsan_atomic8 *a,
127    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
128__tsan_atomic16 __tsan_atomic16_fetch_xor(volatile __tsan_atomic16 *a,
129    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
130__tsan_atomic32 __tsan_atomic32_fetch_xor(volatile __tsan_atomic32 *a,
131    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
132__tsan_atomic64 __tsan_atomic64_fetch_xor(volatile __tsan_atomic64 *a,
133    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
134__tsan_atomic128 __tsan_atomic128_fetch_xor(volatile __tsan_atomic128 *a,
135    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
136
137__tsan_atomic8 __tsan_atomic8_fetch_nand(volatile __tsan_atomic8 *a,
138    __tsan_atomic8 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
139__tsan_atomic16 __tsan_atomic16_fetch_nand(volatile __tsan_atomic16 *a,
140    __tsan_atomic16 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
141__tsan_atomic32 __tsan_atomic32_fetch_nand(volatile __tsan_atomic32 *a,
142    __tsan_atomic32 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
143__tsan_atomic64 __tsan_atomic64_fetch_nand(volatile __tsan_atomic64 *a,
144    __tsan_atomic64 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
145__tsan_atomic128 __tsan_atomic128_fetch_nand(volatile __tsan_atomic128 *a,
146    __tsan_atomic128 v, __tsan_memory_order mo) INTERFACE_ATTRIBUTE;
147
148int __tsan_atomic8_compare_exchange_weak(volatile __tsan_atomic8 *a,
149    __tsan_atomic8 *c, __tsan_atomic8 v, __tsan_memory_order mo,
150    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
151int __tsan_atomic16_compare_exchange_weak(volatile __tsan_atomic16 *a,
152    __tsan_atomic16 *c, __tsan_atomic16 v, __tsan_memory_order mo,
153    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
154int __tsan_atomic32_compare_exchange_weak(volatile __tsan_atomic32 *a,
155    __tsan_atomic32 *c, __tsan_atomic32 v, __tsan_memory_order mo,
156    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
157int __tsan_atomic64_compare_exchange_weak(volatile __tsan_atomic64 *a,
158    __tsan_atomic64 *c, __tsan_atomic64 v, __tsan_memory_order mo,
159    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
160int __tsan_atomic128_compare_exchange_weak(volatile __tsan_atomic128 *a,
161    __tsan_atomic128 *c, __tsan_atomic128 v, __tsan_memory_order mo,
162    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
163
164int __tsan_atomic8_compare_exchange_strong(volatile __tsan_atomic8 *a,
165    __tsan_atomic8 *c, __tsan_atomic8 v, __tsan_memory_order mo,
166    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
167int __tsan_atomic16_compare_exchange_strong(volatile __tsan_atomic16 *a,
168    __tsan_atomic16 *c, __tsan_atomic16 v, __tsan_memory_order mo,
169    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
170int __tsan_atomic32_compare_exchange_strong(volatile __tsan_atomic32 *a,
171    __tsan_atomic32 *c, __tsan_atomic32 v, __tsan_memory_order mo,
172    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
173int __tsan_atomic64_compare_exchange_strong(volatile __tsan_atomic64 *a,
174    __tsan_atomic64 *c, __tsan_atomic64 v, __tsan_memory_order mo,
175    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
176int __tsan_atomic128_compare_exchange_strong(volatile __tsan_atomic128 *a,
177    __tsan_atomic128 *c, __tsan_atomic128 v, __tsan_memory_order mo,
178    __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
179
180__tsan_atomic8 __tsan_atomic8_compare_exchange_val(
181    volatile __tsan_atomic8 *a, __tsan_atomic8 c, __tsan_atomic8 v,
182    __tsan_memory_order mo, __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
183__tsan_atomic16 __tsan_atomic16_compare_exchange_val(
184    volatile __tsan_atomic16 *a, __tsan_atomic16 c, __tsan_atomic16 v,
185    __tsan_memory_order mo, __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
186__tsan_atomic32 __tsan_atomic32_compare_exchange_val(
187    volatile __tsan_atomic32 *a, __tsan_atomic32 c, __tsan_atomic32 v,
188    __tsan_memory_order mo, __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
189__tsan_atomic64 __tsan_atomic64_compare_exchange_val(
190    volatile __tsan_atomic64 *a, __tsan_atomic64 c, __tsan_atomic64 v,
191    __tsan_memory_order mo, __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
192__tsan_atomic128 __tsan_atomic128_compare_exchange_val(
193    volatile __tsan_atomic128 *a, __tsan_atomic128 c, __tsan_atomic128 v,
194    __tsan_memory_order mo, __tsan_memory_order fail_mo) INTERFACE_ATTRIBUTE;
195
196void __tsan_atomic_thread_fence(__tsan_memory_order mo) INTERFACE_ATTRIBUTE;
197void __tsan_atomic_signal_fence(__tsan_memory_order mo) INTERFACE_ATTRIBUTE;
198
199#ifdef __cplusplus
200}  // extern "C"
201#endif
202
203#undef INTERFACE_ATTRIBUTE
204
205#endif  // #ifndef TSAN_INTERFACE_ATOMIC_H
206