OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 for compiler-based | 5 // This file is an internal atomic implementation for compiler-based |
6 // ThreadSanitizer. Use base/atomicops.h instead. | 6 // ThreadSanitizer. Use base/atomicops.h instead. |
7 | 7 |
8 #ifndef BASE_ATOMICOPS_INTERNALS_TSAN_H_ | 8 #ifndef BASE_ATOMICOPS_INTERNALS_TSAN_H_ |
9 #define BASE_ATOMICOPS_INTERNALS_TSAN_H_ | 9 #define BASE_ATOMICOPS_INTERNALS_TSAN_H_ |
10 | 10 |
11 #include "base/base_export.h" | |
12 | |
13 // This struct is not part of the public API of this module; clients may not | |
14 // use it. (However, it's exported via BASE_EXPORT because clients implicitly | |
15 // do use it at link time by inlining these functions.) | |
16 // Features of this x86. Values may not be correct before main() is run, | |
17 // but are set conservatively. | |
18 struct AtomicOps_x86CPUFeatureStruct { | |
19 bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence | |
20 // after acquire compare-and-swap. | |
21 }; | |
22 BASE_EXPORT extern struct AtomicOps_x86CPUFeatureStruct | |
23 AtomicOps_Internalx86CPUFeatures; | |
24 | |
25 #define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") | |
26 | |
27 #include <sanitizer/tsan_interface_atomic.h> | 11 #include <sanitizer/tsan_interface_atomic.h> |
28 | 12 |
29 namespace base { | 13 namespace base { |
30 namespace subtle { | 14 namespace subtle { |
31 | 15 |
32 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, | 16 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
33 Atomic32 old_value, | 17 Atomic32 old_value, |
34 Atomic32 new_value) { | 18 Atomic32 new_value) { |
35 Atomic32 cmp = old_value; | 19 Atomic32 cmp = old_value; |
36 __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value, | 20 __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 return cmp; | 176 return cmp; |
193 } | 177 } |
194 | 178 |
195 inline void MemoryBarrier() { | 179 inline void MemoryBarrier() { |
196 __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); | 180 __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); |
197 } | 181 } |
198 | 182 |
199 } // namespace base::subtle | 183 } // namespace base::subtle |
200 } // namespace base | 184 } // namespace base |
201 | 185 |
202 #undef ATOMICOPS_COMPILER_BARRIER | |
203 | |
204 #endif // BASE_ATOMICOPS_INTERNALS_TSAN_H_ | 186 #endif // BASE_ATOMICOPS_INTERNALS_TSAN_H_ |
OLD | NEW |