clang API Documentation
00001 /*===---- stdatomic.h - Standard header for atomic types and operations -----=== 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy 00004 * of this software and associated documentation files (the "Software"), to deal 00005 * in the Software without restriction, including without limitation the rights 00006 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00007 * copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in 00011 * all copies or substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00014 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00015 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00016 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00017 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00018 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00019 * THE SOFTWARE. 00020 * 00021 *===-----------------------------------------------------------------------=== 00022 */ 00023 00024 #ifndef __CLANG_STDATOMIC_H 00025 #define __CLANG_STDATOMIC_H 00026 00027 /* If we're hosted, fall back to the system's stdatomic.h. FreeBSD, for 00028 * example, already has a Clang-compatible stdatomic.h header. 00029 */ 00030 #if __STDC_HOSTED__ && __has_include_next(<stdatomic.h>) 00031 # include_next <stdatomic.h> 00032 #else 00033 00034 #include <stddef.h> 00035 #include <stdint.h> 00036 00037 #ifdef __cplusplus 00038 extern "C" { 00039 #endif 00040 00041 /* 7.17.1 Introduction */ 00042 00043 #define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE 00044 #define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE 00045 #define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE 00046 #define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE 00047 #define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE 00048 #define ATOMIC_SHORT_T_LOCK_FREE __GCC_ATOMIC_SHORT_T_LOCK_FREE 00049 #define ATOMIC_INT_T_LOCK_FREE __GCC_ATOMIC_INT_T_LOCK_FREE 00050 #define ATOMIC_LONG_T_LOCK_FREE __GCC_ATOMIC_LONG_T_LOCK_FREE 00051 #define ATOMIC_LLONG_T_LOCK_FREE __GCC_ATOMIC_LLONG_T_LOCK_FREE 00052 #define ATOMIC_POINTER_T_LOCK_FREE __GCC_ATOMIC_POINTER_T_LOCK_FREE 00053 00054 /* 7.17.2 Initialization */ 00055 00056 #define ATOMIC_VAR_INIT(value) (value) 00057 #define atomic_init __c11_atomic_init 00058 00059 /* 7.17.3 Order and consistency */ 00060 00061 typedef enum memory_order { 00062 memory_order_relaxed = __ATOMIC_RELAXED, 00063 memory_order_consume = __ATOMIC_CONSUME, 00064 memory_order_acquire = __ATOMIC_ACQUIRE, 00065 memory_order_release = __ATOMIC_RELEASE, 00066 memory_order_acq_rel = __ATOMIC_ACQ_REL, 00067 memory_order_seq_cst = __ATOMIC_SEQ_CST 00068 } memory_order; 00069 00070 #define kill_dependency(y) (y) 00071 00072 /* 7.17.4 Fences */ 00073 00074 // These should be provided by the libc implementation. 00075 void atomic_thread_fence(memory_order); 00076 void atomic_signal_fence(memory_order); 00077 00078 #define atomic_thread_fence(order) __c11_atomic_thread_fence(order) 00079 #define atomic_signal_fence(order) __c11_atomic_signal_fence(order) 00080 00081 /* 7.17.5 Lock-free property */ 00082 00083 #define atomic_is_lock_free(obj) __c11_atomic_is_lock_free(sizeof(*(obj))) 00084 00085 /* 7.17.6 Atomic integer types */ 00086 00087 #ifdef __cplusplus 00088 typedef _Atomic(bool) atomic_bool; 00089 #else 00090 typedef _Atomic(_Bool) atomic_bool; 00091 #endif 00092 typedef _Atomic(char) atomic_char; 00093 typedef _Atomic(signed char) atomic_schar; 00094 typedef _Atomic(unsigned char) atomic_uchar; 00095 typedef _Atomic(short) atomic_short; 00096 typedef _Atomic(unsigned short) atomic_ushort; 00097 typedef _Atomic(int) atomic_int; 00098 typedef _Atomic(unsigned int) atomic_uint; 00099 typedef _Atomic(long) atomic_long; 00100 typedef _Atomic(unsigned long) atomic_ulong; 00101 typedef _Atomic(long long) atomic_llong; 00102 typedef _Atomic(unsigned long long) atomic_ullong; 00103 typedef _Atomic(uint_least16_t) atomic_char16_t; 00104 typedef _Atomic(uint_least32_t) atomic_char32_t; 00105 typedef _Atomic(wchar_t) atomic_wchar_t; 00106 typedef _Atomic(int_least8_t) atomic_int_least8_t; 00107 typedef _Atomic(uint_least8_t) atomic_uint_least8_t; 00108 typedef _Atomic(int_least16_t) atomic_int_least16_t; 00109 typedef _Atomic(uint_least16_t) atomic_uint_least16_t; 00110 typedef _Atomic(int_least32_t) atomic_int_least32_t; 00111 typedef _Atomic(uint_least32_t) atomic_uint_least32_t; 00112 typedef _Atomic(int_least64_t) atomic_int_least64_t; 00113 typedef _Atomic(uint_least64_t) atomic_uint_least64_t; 00114 typedef _Atomic(int_fast8_t) atomic_int_fast8_t; 00115 typedef _Atomic(uint_fast8_t) atomic_uint_fast8_t; 00116 typedef _Atomic(int_fast16_t) atomic_int_fast16_t; 00117 typedef _Atomic(uint_fast16_t) atomic_uint_fast16_t; 00118 typedef _Atomic(int_fast32_t) atomic_int_fast32_t; 00119 typedef _Atomic(uint_fast32_t) atomic_uint_fast32_t; 00120 typedef _Atomic(int_fast64_t) atomic_int_fast64_t; 00121 typedef _Atomic(uint_fast64_t) atomic_uint_fast64_t; 00122 typedef _Atomic(intptr_t) atomic_intptr_t; 00123 typedef _Atomic(uintptr_t) atomic_uintptr_t; 00124 typedef _Atomic(size_t) atomic_size_t; 00125 typedef _Atomic(ptrdiff_t) atomic_ptrdiff_t; 00126 typedef _Atomic(intmax_t) atomic_intmax_t; 00127 typedef _Atomic(uintmax_t) atomic_uintmax_t; 00128 00129 /* 7.17.7 Operations on atomic types */ 00130 00131 #define atomic_store(object, desired) __c11_atomic_store(object, desired, __ATOMIC_SEQ_CST) 00132 #define atomic_store_explicit __c11_atomic_store 00133 00134 #define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST) 00135 #define atomic_load_explicit __c11_atomic_load 00136 00137 #define atomic_exchange(object, desired) __c11_atomic_exchange(object, desired, __ATOMIC_SEQ_CST) 00138 #define atomic_exchange_explicit __c11_atomic_exchange 00139 00140 #define atomic_compare_exchange_strong(object, expected, desired) __c11_atomic_compare_exchange_strong(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) 00141 #define atomic_compare_exchange_strong_explicit __c11_atomic_compare_exchange_strong 00142 00143 #define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) 00144 #define atomic_compare_exchange_weak_explicit __c11_atomic_compare_exchange_weak 00145 00146 #define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST) 00147 #define atomic_fetch_add_explicit __c11_atomic_fetch_add 00148 00149 #define atomic_fetch_sub(object, operand) __c11_atomic_fetch_sub(object, operand, __ATOMIC_SEQ_CST) 00150 #define atomic_fetch_sub_explicit __c11_atomic_fetch_sub 00151 00152 #define atomic_fetch_or(object, operand) __c11_atomic_fetch_or(object, operand, __ATOMIC_SEQ_CST) 00153 #define atomic_fetch_or_explicit __c11_atomic_fetch_or 00154 00155 #define atomic_fetch_xor(object, operand) __c11_atomic_fetch_xor(object, operand, __ATOMIC_SEQ_CST) 00156 #define atomic_fetch_xor_explicit __c11_atomic_fetch_xor 00157 00158 #define atomic_fetch_and(object, operand) __c11_atomic_fetch_and(object, operand, __ATOMIC_SEQ_CST) 00159 #define atomic_fetch_and_explicit __c11_atomic_fetch_and 00160 00161 /* 7.17.8 Atomic flag type and operations */ 00162 00163 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag; 00164 00165 #define ATOMIC_FLAG_INIT { 0 } 00166 00167 // These should be provided by the libc implementation. 00168 #ifdef __cplusplus 00169 bool atomic_flag_test_and_set(volatile atomic_flag *); 00170 bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); 00171 #else 00172 _Bool atomic_flag_test_and_set(volatile atomic_flag *); 00173 _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *, memory_order); 00174 #endif 00175 void atomic_flag_clear(volatile atomic_flag *); 00176 void atomic_flag_clear_explicit(volatile atomic_flag *, memory_order); 00177 00178 #define atomic_flag_test_and_set(object) __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST) 00179 #define atomic_flag_test_and_set_explicit(object, order) __c11_atomic_exchange(&(object)->_Value, 1, order) 00180 00181 #define atomic_flag_clear(object) __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST) 00182 #define atomic_flag_clear_explicit(object, order) __c11_atomic_store(&(object)->_Value, 0, order) 00183 00184 #ifdef __cplusplus 00185 } 00186 #endif 00187 00188 #endif /* __STDC_HOSTED__ */ 00189 #endif /* __CLANG_STDATOMIC_H */ 00190