OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2012 Google Inc. All rights reserved. | 2 // Copyright 2012 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 116 Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
117 Atomic32 increment); | 117 Atomic32 increment); |
118 | 118 |
119 // These following lower-level operations are typically useful only to people | 119 // These following lower-level operations are typically useful only to people |
120 // implementing higher-level synchronization operations like spinlocks, | 120 // implementing higher-level synchronization operations like spinlocks, |
121 // mutexes, and condition-variables. They combine CompareAndSwap(), a load, or | 121 // mutexes, and condition-variables. They combine CompareAndSwap(), a load, or |
122 // a store with appropriate memory-ordering instructions. "Acquire" operations | 122 // a store with appropriate memory-ordering instructions. "Acquire" operations |
123 // ensure that no later memory access can be reordered ahead of the operation. | 123 // ensure that no later memory access can be reordered ahead of the operation. |
124 // "Release" operations ensure that no previous memory access can be reordered | 124 // "Release" operations ensure that no previous memory access can be reordered |
125 // after the operation. "Barrier" operations have both "Acquire" and "Release" | 125 // after the operation. "Barrier" operations have both "Acquire" and "Release" |
126 // semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no | 126 // semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory |
127 // memory access. | 127 // access. |
128 Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, | 128 Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, |
129 Atomic32 old_value, | 129 Atomic32 old_value, |
130 Atomic32 new_value); | 130 Atomic32 new_value); |
131 Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, | 131 Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, |
132 Atomic32 old_value, | 132 Atomic32 old_value, |
133 Atomic32 new_value); | 133 Atomic32 new_value); |
134 | 134 |
135 // This function was renamed from MemoryBarrier to MemoryBarrierInternal | 135 #if defined(__MINGW32__) && defined(MemoryBarrier) |
136 // because MemoryBarrier is a define in Windows ARM builds and we do not | 136 #undef MemoryBarrier |
137 // undefine it because we call it from this function. | 137 #endif |
138 void MemoryBarrierInternal(); | 138 void MemoryBarrier(); |
139 void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); | 139 void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); |
140 void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); | 140 void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); |
141 void Release_Store(volatile Atomic32* ptr, Atomic32 value); | 141 void Release_Store(volatile Atomic32* ptr, Atomic32 value); |
142 | 142 |
143 Atomic32 NoBarrier_Load(volatile const Atomic32* ptr); | 143 Atomic32 NoBarrier_Load(volatile const Atomic32* ptr); |
144 Atomic32 Acquire_Load(volatile const Atomic32* ptr); | 144 Atomic32 Acquire_Load(volatile const Atomic32* ptr); |
145 Atomic32 Release_Load(volatile const Atomic32* ptr); | 145 Atomic32 Release_Load(volatile const Atomic32* ptr); |
146 | 146 |
147 // 64-bit atomic operations (only available on 64-bit processors). | 147 // 64-bit atomic operations (only available on 64-bit processors). |
148 #ifdef GOOGLE_PROTOBUF_ARCH_64_BIT | 148 #ifdef GOOGLE_PROTOBUF_ARCH_64_BIT |
(...skipping 24 matching lines...) Expand all Loading... |
173 | 173 |
174 // Include our platform specific implementation. | 174 // Include our platform specific implementation. |
175 #define GOOGLE_PROTOBUF_ATOMICOPS_ERROR \ | 175 #define GOOGLE_PROTOBUF_ATOMICOPS_ERROR \ |
176 "Atomic operations are not supported on your platform" | 176 "Atomic operations are not supported on your platform" |
177 | 177 |
178 // ThreadSanitizer, http://clang.llvm.org/docs/ThreadSanitizer.html. | 178 // ThreadSanitizer, http://clang.llvm.org/docs/ThreadSanitizer.html. |
179 #if defined(THREAD_SANITIZER) | 179 #if defined(THREAD_SANITIZER) |
180 #include <google/protobuf/stubs/atomicops_internals_tsan.h> | 180 #include <google/protobuf/stubs/atomicops_internals_tsan.h> |
181 // MSVC. | 181 // MSVC. |
182 #elif defined(_MSC_VER) | 182 #elif defined(_MSC_VER) |
183 #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) || d
efined(GOOGLE_PROTOBUF_ARCH_ARM) | 183 #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) |
184 #include <google/protobuf/stubs/atomicops_internals_x86_msvc.h> | 184 #include <google/protobuf/stubs/atomicops_internals_x86_msvc.h> |
185 #else | 185 #else |
186 #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR | 186 #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR |
187 #endif | 187 #endif |
188 | 188 |
189 // Solaris | 189 // Solaris |
190 #elif defined(GOOGLE_PROTOBUF_OS_SOLARIS) | 190 #elif defined(GOOGLE_PROTOBUF_OS_SOLARIS) |
191 #include <google/protobuf/stubs/atomicops_internals_solaris.h> | 191 #include <google/protobuf/stubs/atomicops_internals_solaris.h> |
192 | 192 |
193 // AIX | 193 // AIX |
194 #elif defined(GOOGLE_PROTOBUF_OS_AIX) | 194 #elif defined(GOOGLE_PROTOBUF_OS_AIX) |
195 #include <google/protobuf/stubs/atomicops_internals_power.h> | 195 #include <google/protobuf/stubs/atomicops_internals_power.h> |
196 | 196 |
197 // Apple. | 197 // Apple. |
198 #elif defined(GOOGLE_PROTOBUF_OS_APPLE) | 198 #elif defined(GOOGLE_PROTOBUF_OS_APPLE) |
199 #if __has_feature(cxx_atomic) || _GNUC_VER >= 407 | |
200 #include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h> | |
201 #else // __has_feature(cxx_atomic) || _GNUC_VER >= 407 | |
202 #include <google/protobuf/stubs/atomicops_internals_macosx.h> | 199 #include <google/protobuf/stubs/atomicops_internals_macosx.h> |
203 #endif // __has_feature(cxx_atomic) || _GNUC_VER >= 407 | |
204 | 200 |
205 // GCC. | 201 // GCC. |
206 #elif defined(__GNUC__) | 202 #elif defined(__GNUC__) |
207 #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) | 203 #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) |
208 #include <google/protobuf/stubs/atomicops_internals_x86_gcc.h> | 204 #include <google/protobuf/stubs/atomicops_internals_x86_gcc.h> |
209 #elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__) | 205 #elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__) |
210 #if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) | |
211 #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> | |
212 #else | |
213 #include <google/protobuf/stubs/atomicops_internals_arm_gcc.h> | 206 #include <google/protobuf/stubs/atomicops_internals_arm_gcc.h> |
214 #endif | |
215 #elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64) | 207 #elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64) |
216 #include <google/protobuf/stubs/atomicops_internals_arm64_gcc.h> | 208 #include <google/protobuf/stubs/atomicops_internals_arm64_gcc.h> |
217 #elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX) | 209 #elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX) |
218 #include <google/protobuf/stubs/atomicops_internals_arm_qnx.h> | 210 #include <google/protobuf/stubs/atomicops_internals_arm_qnx.h> |
219 #elif defined(GOOGLE_PROTOBUF_ARCH_MIPS) || defined(GOOGLE_PROTOBUF_ARCH_MIPS64) | 211 #elif defined(GOOGLE_PROTOBUF_ARCH_MIPS) || defined(GOOGLE_PROTOBUF_ARCH_MIPS64) |
220 #include <google/protobuf/stubs/atomicops_internals_mips_gcc.h> | 212 #include <google/protobuf/stubs/atomicops_internals_mips_gcc.h> |
221 #elif defined(GOOGLE_PROTOBUF_ARCH_POWER) | 213 #elif defined(GOOGLE_PROTOBUF_ARCH_POWER) |
222 #include <google/protobuf/stubs/atomicops_internals_power.h> | 214 #include <google/protobuf/stubs/atomicops_internals_power.h> |
223 #elif defined(__native_client__) | 215 #elif defined(__native_client__) |
224 #include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h> | 216 #include <google/protobuf/stubs/atomicops_internals_pnacl.h> |
225 #elif defined(GOOGLE_PROTOBUF_ARCH_PPC) | 217 #elif defined(GOOGLE_PROTOBUF_ARCH_PPC) |
226 #include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h> | 218 #include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h> |
227 #elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) | 219 #elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) |
228 #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> | 220 #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> |
229 #elif defined(__clang__) | 221 #elif defined(__clang__) |
230 #if __has_extension(c_atomic) | 222 #if __has_extension(c_atomic) |
231 #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> | 223 #include <google/protobuf/stubs/atomicops_internals_generic_gcc.h> |
232 #else | 224 #else |
233 #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR | 225 #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR |
234 #endif | 226 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
245 // compatible with our other Atomic* types. | 237 // compatible with our other Atomic* types. |
246 #if defined(GOOGLE_PROTOBUF_OS_APPLE) | 238 #if defined(GOOGLE_PROTOBUF_OS_APPLE) |
247 #include <google/protobuf/stubs/atomicops_internals_atomicword_compat.h> | 239 #include <google/protobuf/stubs/atomicops_internals_atomicword_compat.h> |
248 #endif | 240 #endif |
249 | 241 |
250 #undef GOOGLE_PROTOBUF_ATOMICOPS_ERROR | 242 #undef GOOGLE_PROTOBUF_ATOMICOPS_ERROR |
251 | 243 |
252 #endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY | 244 #endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY |
253 | 245 |
254 #endif // GOOGLE_PROTOBUF_ATOMICOPS_H_ | 246 #endif // GOOGLE_PROTOBUF_ATOMICOPS_H_ |
OLD | NEW |