Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <bits/c++config.h>
00030 #include <stddef.h>
00031 #include <stdbool.h>
00032
00033 #ifndef _GLIBCXX_ATOMIC_BASE_H
00034 #define _GLIBCXX_ATOMIC_BASE_H 1
00035
00036 _GLIBCXX_BEGIN_NAMESPACE(std)
00037 _GLIBCXX_BEGIN_EXTERN_C
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 typedef enum memory_order
00048 {
00049 memory_order_relaxed,
00050 memory_order_consume,
00051 memory_order_acquire,
00052 memory_order_release,
00053 memory_order_acq_rel,
00054 memory_order_seq_cst
00055 } memory_order;
00056
00057
00058 typedef struct __atomic_flag_base
00059 {
00060 bool _M_i;
00061 } __atomic_flag_base;
00062
00063 #define ATOMIC_FLAG_INIT { false }
00064
00065
00066 #if defined(_GLIBCXX_ATOMIC_BUILTINS_1) && defined(_GLIBCXX_ATOMIC_BUILTINS_2) \
00067 && defined(_GLIBCXX_ATOMIC_BUILTINS_4) && defined(_GLIBCXX_ATOMIC_BUILTINS_8)
00068 # define _GLIBCXX_ATOMIC_PROPERTY 2
00069 # define _GLIBCXX_ATOMIC_NAMESPACE __atomic2
00070 #elif defined(_GLIBCXX_ATOMIC_BUILTINS_1)
00071 # define _GLIBCXX_ATOMIC_PROPERTY 1
00072 # define _GLIBCXX_ATOMIC_NAMESPACE __atomic1
00073 #else
00074 # define _GLIBCXX_ATOMIC_PROPERTY 0
00075 # define _GLIBCXX_ATOMIC_NAMESPACE __atomic0
00076 #endif
00077
00078 #define ATOMIC_INTEGRAL_LOCK_FREE _GLIBCXX_ATOMIC_PROPERTY
00079 #define ATOMIC_ADDRESS_LOCK_FREE _GLIBCXX_ATOMIC_PROPERTY
00080
00081
00082
00083
00084
00085 #ifdef __cplusplus
00086 inline namespace _GLIBCXX_ATOMIC_NAMESPACE { }
00087 # include <bits/atomicfwd_cxx.h>
00088 #else
00089 # include <bits/atomicfwd_c.h>
00090 #endif
00091
00092
00093 typedef atomic_schar atomic_int_least8_t;
00094 typedef atomic_uchar atomic_uint_least8_t;
00095 typedef atomic_short atomic_int_least16_t;
00096 typedef atomic_ushort atomic_uint_least16_t;
00097 typedef atomic_int atomic_int_least32_t;
00098 typedef atomic_uint atomic_uint_least32_t;
00099 typedef atomic_llong atomic_int_least64_t;
00100 typedef atomic_ullong atomic_uint_least64_t;
00101
00102 typedef atomic_schar atomic_int_fast8_t;
00103 typedef atomic_uchar atomic_uint_fast8_t;
00104 typedef atomic_short atomic_int_fast16_t;
00105 typedef atomic_ushort atomic_uint_fast16_t;
00106 typedef atomic_int atomic_int_fast32_t;
00107 typedef atomic_uint atomic_uint_fast32_t;
00108 typedef atomic_llong atomic_int_fast64_t;
00109 typedef atomic_ullong atomic_uint_fast64_t;
00110
00111 typedef atomic_long atomic_intptr_t;
00112 typedef atomic_ulong atomic_uintptr_t;
00113
00114 typedef atomic_long atomic_ssize_t;
00115 typedef atomic_ulong atomic_size_t;
00116
00117 typedef atomic_llong atomic_intmax_t;
00118 typedef atomic_ullong atomic_uintmax_t;
00119
00120 typedef atomic_long atomic_ptrdiff_t;
00121
00122
00123 bool
00124 atomic_flag_test_and_set_explicit(__atomic_flag_base*, memory_order)
00125 _GLIBCXX_NOTHROW;
00126
00127 inline bool
00128 atomic_flag_test_and_set(__atomic_flag_base* __a)
00129 { return atomic_flag_test_and_set_explicit(__a, memory_order_seq_cst); }
00130
00131 void
00132 atomic_flag_clear_explicit(__atomic_flag_base*, memory_order)
00133 _GLIBCXX_NOTHROW;
00134
00135 inline void
00136 atomic_flag_clear(__atomic_flag_base* __a)
00137 { atomic_flag_clear_explicit(__a, memory_order_seq_cst); }
00138
00139 void
00140 __atomic_flag_wait_explicit(__atomic_flag_base*, memory_order)
00141 _GLIBCXX_NOTHROW;
00142
00143 _GLIBCXX_CONST __atomic_flag_base*
00144 __atomic_flag_for_address(const void* __z) _GLIBCXX_NOTHROW;
00145
00146
00147 #define _ATOMIC_LOAD_(__a, __x) \
00148 ({__typeof__ _ATOMIC_MEMBER_* __p = &_ATOMIC_MEMBER_; \
00149 atomic_flag* __g = __atomic_flag_for_address(__p); \
00150 __atomic_flag_wait_explicit(__g, __x); \
00151 __typeof__ _ATOMIC_MEMBER_ __r = *__p; \
00152 atomic_flag_clear_explicit(__g, __x); \
00153 __r; })
00154
00155 #define _ATOMIC_STORE_(__a, __m, __x) \
00156 ({__typeof__ _ATOMIC_MEMBER_* __p = &_ATOMIC_MEMBER_; \
00157 __typeof__(__m) __v = (__m); \
00158 atomic_flag* __g = __atomic_flag_for_address(__p); \
00159 __atomic_flag_wait_explicit(__g, __x); \
00160 *__p = __v; \
00161 atomic_flag_clear_explicit(__g, __x); \
00162 __v; })
00163
00164 #define _ATOMIC_MODIFY_(__a, __o, __m, __x) \
00165 ({__typeof__ _ATOMIC_MEMBER_* __p = &_ATOMIC_MEMBER_; \
00166 __typeof__(__m) __v = (__m); \
00167 atomic_flag* __g = __atomic_flag_for_address(__p); \
00168 __atomic_flag_wait_explicit(__g, __x); \
00169 __typeof__ _ATOMIC_MEMBER_ __r = *__p; \
00170 *__p __o __v; \
00171 atomic_flag_clear_explicit(__g, __x); \
00172 __r; })
00173
00174 #define _ATOMIC_CMPEXCHNG_(__a, __e, __m, __x) \
00175 ({__typeof__ _ATOMIC_MEMBER_* __p = &_ATOMIC_MEMBER_; \
00176 __typeof__(__e) __q = (__e); \
00177 __typeof__(__m) __v = (__m); \
00178 bool __r; \
00179 atomic_flag* __g = __atomic_flag_for_address(__p); \
00180 __atomic_flag_wait_explicit(__g, __x); \
00181 __typeof__ _ATOMIC_MEMBER_ __t__ = *__p; \
00182 if (__t__ == *__q) { *__p = __v; __r = true; } \
00183 else { *__q = __t__; __r = false; } \
00184 atomic_flag_clear_explicit(__g, __x); \
00185 __r; })
00186
00187
00188
00189 _GLIBCXX_END_EXTERN_C
00190 _GLIBCXX_END_NAMESPACE
00191
00192
00193 #ifdef __cplusplus
00194
00195 #include <atomic>
00196
00197 using std::memory_order;
00198 using std::memory_order_relaxed;
00199 using std::memory_order_consume;
00200 using std::memory_order_acquire;
00201 using std::memory_order_release;
00202 using std::memory_order_acq_rel;
00203 using std::memory_order_seq_cst;
00204 using std::atomic_flag;
00205 using std::atomic_bool;
00206 using std::atomic_char;
00207 using std::atomic_schar;
00208 using std::atomic_uchar;
00209 using std::atomic_short;
00210 using std::atomic_ushort;
00211 using std::atomic_int;
00212 using std::atomic_uint;
00213 using std::atomic_long;
00214 using std::atomic_ulong;
00215 using std::atomic_llong;
00216 using std::atomic_ullong;
00217 using std::atomic_wchar_t;
00218 using std::atomic_char16_t;
00219 using std::atomic_char32_t;
00220 using std::atomic_address;
00221 using std::atomic;
00222 #endif
00223
00224 #endif