OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file is an internal atomic implementation, use atomicops.h instead. | 5 // This file is an internal atomic implementation, use atomicops.h instead. |
6 // | 6 // |
7 // This implementation uses C++11 atomics' member functions. The code base is | 7 // This implementation uses C++11 atomics' member functions. The code base is |
8 // currently written assuming atomicity revolves around accesses instead of | 8 // currently written assuming atomicity revolves around accesses instead of |
9 // C++11's memory locations. The burden is on the programmer to ensure that all | 9 // C++11's memory locations. The burden is on the programmer to ensure that all |
10 // memory locations accessed atomically are never accessed non-atomically (tsan | 10 // memory locations accessed atomically are never accessed non-atomically (tsan |
(...skipping 16 matching lines...) Expand all Loading... |
27 // * Atomic increment is expected to return the post-incremented value, whereas | 27 // * Atomic increment is expected to return the post-incremented value, whereas |
28 // C11 fetch add returns the previous value. The implementation therefore | 28 // C11 fetch add returns the previous value. The implementation therefore |
29 // needs to increment twice (which the compiler should be able to detect and | 29 // needs to increment twice (which the compiler should be able to detect and |
30 // optimize). | 30 // optimize). |
31 | 31 |
32 #ifndef BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ | 32 #ifndef BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ |
33 #define BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ | 33 #define BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ |
34 | 34 |
35 #include <atomic> | 35 #include <atomic> |
36 | 36 |
| 37 #include "build/build_config.h" |
| 38 |
37 namespace base { | 39 namespace base { |
38 namespace subtle { | 40 namespace subtle { |
39 | 41 |
40 // This implementation is transitional and maintains the original API for | 42 // This implementation is transitional and maintains the original API for |
41 // atomicops.h. This requires casting memory locations to the atomic types, and | 43 // atomicops.h. This requires casting memory locations to the atomic types, and |
42 // assumes that the API and the C++11 implementation are layout-compatible, | 44 // assumes that the API and the C++11 implementation are layout-compatible, |
43 // which isn't true for all implementations or hardware platforms. The static | 45 // which isn't true for all implementations or hardware platforms. The static |
44 // assertion should detect this issue, were it to fire then this header | 46 // assertion should detect this issue, were it to fire then this header |
45 // shouldn't be used. | 47 // shouldn't be used. |
46 // | 48 // |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 inline Atomic64 Release_Load(volatile const Atomic64* ptr) { | 220 inline Atomic64 Release_Load(volatile const Atomic64* ptr) { |
219 MemoryBarrier(); | 221 MemoryBarrier(); |
220 return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed); | 222 return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed); |
221 } | 223 } |
222 | 224 |
223 #endif // defined(ARCH_CPU_64_BITS) | 225 #endif // defined(ARCH_CPU_64_BITS) |
224 } // namespace subtle | 226 } // namespace subtle |
225 } // namespace base | 227 } // namespace base |
226 | 228 |
227 #endif // BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ | 229 #endif // BASE_ATOMICOPS_INTERNALS_PORTABLE_H_ |
OLD | NEW |