blob: b7dac4a4438d68d3178fac31ff0ef891925d737b [file] [log] [blame]
Logan Chiendf4f7662019-09-04 16:45:23 -07001/*-
2 * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
3 * David Chisnall <theraven@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#ifndef _STDATOMIC_H_
31#define _STDATOMIC_H_
32
33#include <sys/cdefs.h>
34
35#if defined(__cplusplus) && __cplusplus >= 201103L && __has_include(<atomic>)
36# if __has_feature(cxx_atomic)
37# define _STDATOMIC_HAVE_ATOMIC
38# endif
39#endif
40
41#ifdef _STDATOMIC_HAVE_ATOMIC
42
43/* We have a usable C++ <atomic>; use it instead. */
44
45#include <atomic>
46
47#undef _Atomic
48 /* Also defined by <atomic> for gcc. But not used in macros. */
49 /* Also a clang intrinsic. */
50 /* Should not be used by client code before this file is */
51 /* included. The definitions in <atomic> themselves see */
52 /* the old definition, as they should. */
53 /* Client code sees the following definition. */
54
55#define _Atomic(t) std::atomic<t>
56
57using std::atomic_is_lock_free;
58using std::atomic_init;
59using std::atomic_store;
60using std::atomic_store_explicit;
61using std::atomic_load;
62using std::atomic_load_explicit;
63using std::atomic_exchange;
64using std::atomic_exchange_explicit;
65using std::atomic_compare_exchange_strong;
66using std::atomic_compare_exchange_strong_explicit;
67using std::atomic_compare_exchange_weak;
68using std::atomic_compare_exchange_weak_explicit;
69using std::atomic_fetch_add;
70using std::atomic_fetch_add_explicit;
71using std::atomic_fetch_sub;
72using std::atomic_fetch_sub_explicit;
73using std::atomic_fetch_or;
74using std::atomic_fetch_or_explicit;
75using std::atomic_fetch_xor;
76using std::atomic_fetch_xor_explicit;
77using std::atomic_fetch_and;
78using std::atomic_fetch_and_explicit;
79using std::atomic_thread_fence;
80using std::atomic_signal_fence;
81
82using std::memory_order;
83using std::memory_order_relaxed;
84using std::memory_order_consume;
85using std::memory_order_acquire;
86using std::memory_order_release;
87using std::memory_order_acq_rel;
88using std::memory_order_seq_cst;
89
90using std::atomic_bool;
91using std::atomic_char;
92using std::atomic_schar;
93using std::atomic_uchar;
94using std::atomic_short;
95using std::atomic_ushort;
96using std::atomic_int;
97using std::atomic_uint;
98using std::atomic_long;
99using std::atomic_ulong;
100using std::atomic_llong;
101using std::atomic_ullong;
102using std::atomic_char16_t;
103using std::atomic_char32_t;
104using std::atomic_wchar_t;
105using std::atomic_int_least8_t;
106using std::atomic_uint_least8_t;
107using std::atomic_int_least16_t;
108using std::atomic_uint_least16_t;
109using std::atomic_int_least32_t;
110using std::atomic_uint_least32_t;
111using std::atomic_int_least64_t;
112using std::atomic_uint_least64_t;
113using std::atomic_int_fast8_t;
114using std::atomic_uint_fast8_t;
115using std::atomic_int_fast16_t;
116using std::atomic_uint_fast16_t;
117using std::atomic_int_fast32_t;
118using std::atomic_uint_fast32_t;
119using std::atomic_int_fast64_t;
120using std::atomic_uint_fast64_t;
121using std::atomic_intptr_t;
122using std::atomic_uintptr_t;
123using std::atomic_size_t;
124using std::atomic_ptrdiff_t;
125using std::atomic_intmax_t;
126using std::atomic_uintmax_t;
127
128#else /* <atomic> unavailable, possibly because this is C, not C++ */
129
130/* Actual implementation is in bits/stdatomic.h since our test code is C++. */
131#include <bits/stdatomic.h>
132
133#endif /* <atomic> unavailable */
134
135#endif /* !_STDATOMIC_H_ */