Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: base/atomicops.h

Issue 636783002: Use C++11 atomics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make AtomicOps_Internalx86CPUFeatures consistent Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // For atomic operations on reference counts, see atomic_refcount.h. 5 // For atomic operations on reference counts, see atomic_refcount.h.
6 // For atomic operations on sequence numbers, see atomic_sequence_num.h. 6 // For atomic operations on sequence numbers, see atomic_sequence_num.h.
7 7
8 // The routines exported by this module are subtle. If you use them, even if 8 // The routines exported by this module are subtle. If you use them, even if
9 // you get the code right, it will depend on careful reasoning about atomicity 9 // you get the code right, it will depend on careful reasoning about atomicity
10 // and memory ordering; it will be less readable, and harder to maintain. If 10 // and memory ordering; it will be less readable, and harder to maintain. If
(...skipping 12 matching lines...) Expand all
23 // NoBarrier_Load() 23 // NoBarrier_Load()
24 // Although there are currently no compiler enforcement, you are encouraged 24 // Although there are currently no compiler enforcement, you are encouraged
25 // to use these. 25 // to use these.
26 // 26 //
27 27
28 #ifndef BASE_ATOMICOPS_H_ 28 #ifndef BASE_ATOMICOPS_H_
29 #define BASE_ATOMICOPS_H_ 29 #define BASE_ATOMICOPS_H_
30 30
31 #include <stdint.h> 31 #include <stdint.h>
32 32
33 #include "base/base_export.h"
33 #include "build/build_config.h" 34 #include "build/build_config.h"
34 35
35 #if defined(OS_WIN) && defined(ARCH_CPU_64_BITS) 36 #if defined(OS_WIN) && defined(ARCH_CPU_64_BITS)
36 // windows.h #defines this (only on x64). This causes problems because the 37 // windows.h #defines this (only on x64). This causes problems because the
37 // public API also uses MemoryBarrier at the public name for this fence. So, on 38 // public API also uses MemoryBarrier at the public name for this fence. So, on
38 // X64, undef it, and call its documented 39 // X64, undef it, and call its documented
39 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) 40 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx)
40 // implementation directly. 41 // implementation directly.
41 #undef MemoryBarrier 42 #undef MemoryBarrier
42 #endif 43 #endif
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void Acquire_Store(volatile Atomic64* ptr, Atomic64 value); 131 void Acquire_Store(volatile Atomic64* ptr, Atomic64 value);
131 void Release_Store(volatile Atomic64* ptr, Atomic64 value); 132 void Release_Store(volatile Atomic64* ptr, Atomic64 value);
132 Atomic64 NoBarrier_Load(volatile const Atomic64* ptr); 133 Atomic64 NoBarrier_Load(volatile const Atomic64* ptr);
133 Atomic64 Acquire_Load(volatile const Atomic64* ptr); 134 Atomic64 Acquire_Load(volatile const Atomic64* ptr);
134 Atomic64 Release_Load(volatile const Atomic64* ptr); 135 Atomic64 Release_Load(volatile const Atomic64* ptr);
135 #endif // ARCH_CPU_64_BITS 136 #endif // ARCH_CPU_64_BITS
136 137
137 } // namespace subtle 138 } // namespace subtle
138 } // namespace base 139 } // namespace base
139 140
141 // The following x86 CPU features are used in atomicops_internals_x86_gcc.h, but
142 // this file is duplicated inside of Chrome: protobuf and tcmalloc rely on the
143 // struct being present at link time. Some parts of Chrome can currently use the
144 // portable interface whereas others still use GCC one. The include guards are
145 // the same as in atomicops_internals_x86_gcc.cc.
146 #if defined(__i386__) || defined(__x86_64__)
147 // This struct is not part of the public API of this module; clients may not
148 // use it. (However, it's exported via BASE_EXPORT because clients implicitly
149 // do use it at link time by inlining these functions.)
150 // Features of this x86. Values may not be correct before main() is run,
151 // but are set conservatively.
152 struct AtomicOps_x86CPUFeatureStruct {
153 bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence
154 // after acquire compare-and-swap.
155 // The following fields are unused by Chrome's base implementation but are
156 // still used by copies of the same code in other parts of the code base. This
157 // causes an ODR violation, and the other code is likely reading invalid
158 // memory.
159 // TODO(jfb) Delete these fields once the rest of the Chrome code base doesn't
160 // depend on them.
161 bool has_sse2; // Processor has SSE2.
162 bool has_cmpxchg16b; // Processor supports cmpxchg16b instructi
163 };
164 BASE_EXPORT extern struct AtomicOps_x86CPUFeatureStruct
165 AtomicOps_Internalx86CPUFeatures;
166 #endif
167
140 // Include our platform specific implementation. 168 // Include our platform specific implementation.
141 #if defined(THREAD_SANITIZER) 169 #if defined(__cplusplus) && (__cplusplus >= 201103L) // C++11
142 #include "base/atomicops_internals_tsan.h" 170 #include "base/atomicops_internals_portable.h"
Dmitry Vyukov 2014/10/08 08:05:44 __cplusplus is not necessary defined under tsan It
143 #elif defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY) 171 #elif defined(OS_WIN) && defined(COMPILER_MSVC) && defined(ARCH_CPU_X86_FAMILY)
144 #include "base/atomicops_internals_x86_msvc.h" 172 #include "base/atomicops_internals_x86_msvc.h"
145 #elif defined(OS_MACOSX) 173 #elif defined(OS_MACOSX)
146 #include "base/atomicops_internals_mac.h" 174 #include "base/atomicops_internals_mac.h"
147 #elif defined(OS_NACL) 175 #elif defined(OS_NACL)
148 #include "base/atomicops_internals_gcc.h" 176 #include "base/atomicops_internals_gcc.h"
149 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARMEL) 177 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARMEL)
150 #include "base/atomicops_internals_arm_gcc.h" 178 #include "base/atomicops_internals_arm_gcc.h"
151 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARM64) 179 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_ARM64)
152 #include "base/atomicops_internals_arm64_gcc.h" 180 #include "base/atomicops_internals_arm64_gcc.h"
153 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY) 181 #elif defined(COMPILER_GCC) && defined(ARCH_CPU_X86_FAMILY)
154 #include "base/atomicops_internals_x86_gcc.h" 182 #include "base/atomicops_internals_x86_gcc.h"
155 #elif defined(COMPILER_GCC) && \ 183 #elif defined(COMPILER_GCC) && \
156 (defined(ARCH_CPU_MIPS_FAMILY) || defined(ARCH_CPU_MIPS64_FAMILY)) 184 (defined(ARCH_CPU_MIPS_FAMILY) || defined(ARCH_CPU_MIPS64_FAMILY))
157 #include "base/atomicops_internals_mips_gcc.h" 185 #include "base/atomicops_internals_mips_gcc.h"
158 #else 186 #else
159 #error "Atomic operations are not supported on your platform" 187 #error "Atomic operations are not supported on your platform"
160 #endif 188 #endif
161 189
162 // On some platforms we need additional declarations to make 190 // On some platforms we need additional declarations to make
163 // AtomicWord compatible with our other Atomic* types. 191 // AtomicWord compatible with our other Atomic* types.
164 #if defined(OS_MACOSX) || defined(OS_OPENBSD) 192 #if defined(OS_MACOSX) || defined(OS_OPENBSD)
165 #include "base/atomicops_internals_atomicword_compat.h" 193 #include "base/atomicops_internals_atomicword_compat.h"
166 #endif 194 #endif
167 195
168 #endif // BASE_ATOMICOPS_H_ 196 #endif // BASE_ATOMICOPS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698