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