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

Side by Side Diff: src/base/atomicops.h

Issue 2438273002: Reland Update implementation of atomics with latest Chromium version but use compiler builtin atomi… (Closed)
Patch Set: fix memory order for release cmpxchg Created 4 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
« no previous file with comments | « BUILD.gn ('k') | src/base/atomicops_internals_arm64_gcc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project 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 // The routines exported by this module are subtle. If you use them, even if 5 // The routines exported by this module are subtle. If you use them, even if
6 // you get the code right, it will depend on careful reasoning about atomicity 6 // you get the code right, it will depend on careful reasoning about atomicity
7 // and memory ordering; it will be less readable, and harder to maintain. If 7 // and memory ordering; it will be less readable, and harder to maintain. If
8 // you plan to use these routines, you should have a good reason, such as solid 8 // you plan to use these routines, you should have a good reason, such as solid
9 // evidence that performance would otherwise suffer, or there being no 9 // evidence that performance would otherwise suffer, or there being no
10 // alternative. You should assume only properties explicitly guaranteed by the 10 // alternative. You should assume only properties explicitly guaranteed by the
11 // specifications in this file. You are almost certainly _not_ writing code 11 // specifications in this file. You are almost certainly _not_ writing code
12 // just for the x86; if you assume x86 semantics, x86 hardware bugs and 12 // just for the x86; if you assume x86 semantics, x86 hardware bugs and
13 // implementations on other archtectures will cause your code to break. If you 13 // implementations on other archtectures will cause your code to break. If you
14 // do not know what you are doing, avoid these routines, and use a Mutex. 14 // do not know what you are doing, avoid these routines, and use a Mutex.
15 // 15 //
16 // It is incorrect to make direct assignments to/from an atomic variable. 16 // It is incorrect to make direct assignments to/from an atomic variable.
17 // You should use one of the Load or Store routines. The NoBarrier 17 // You should use one of the Load or Store routines. The NoBarrier
18 // versions are provided when no barriers are needed: 18 // versions are provided when no barriers are needed:
19 // NoBarrier_Store() 19 // NoBarrier_Store()
20 // NoBarrier_Load() 20 // NoBarrier_Load()
21 // Although there are currently no compiler enforcement, you are encouraged 21 // Although there are currently no compiler enforcement, you are encouraged
22 // to use these. 22 // to use these.
23 // 23 //
24 24
25 #ifndef V8_BASE_ATOMICOPS_H_ 25 #ifndef V8_BASE_ATOMICOPS_H_
26 #define V8_BASE_ATOMICOPS_H_ 26 #define V8_BASE_ATOMICOPS_H_
27 27
28 #include <stdint.h> 28 #include <stdint.h>
29
30 // Small C++ header which defines implementation specific macros used to
31 // identify the STL implementation.
32 // - libc++: captures __config for _LIBCPP_VERSION
33 // - libstdc++: captures bits/c++config.h for __GLIBCXX__
34 #include <cstddef>
35
36 #include "src/base/base-export.h"
29 #include "src/base/build_config.h" 37 #include "src/base/build_config.h"
30 38
31 #if defined(_WIN32) && defined(V8_HOST_ARCH_64_BIT) 39 #if defined(V8_OS_WIN) && defined(V8_HOST_ARCH_64_BIT)
32 // windows.h #defines this (only on x64). This causes problems because the 40 // windows.h #defines this (only on x64). This causes problems because the
33 // public API also uses MemoryBarrier at the public name for this fence. So, on 41 // public API also uses MemoryBarrier at the public name for this fence. So, on
34 // X64, undef it, and call its documented 42 // X64, undef it, and call its documented
35 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) 43 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx)
36 // implementation directly. 44 // implementation directly.
37 #undef MemoryBarrier 45 #undef MemoryBarrier
38 #endif 46 #endif
39 47
40 namespace v8 { 48 namespace v8 {
41 namespace base { 49 namespace base {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, 101 Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
94 Atomic32 old_value, 102 Atomic32 old_value,
95 Atomic32 new_value); 103 Atomic32 new_value);
96 Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, 104 Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
97 Atomic32 old_value, 105 Atomic32 old_value,
98 Atomic32 new_value); 106 Atomic32 new_value);
99 107
100 void MemoryBarrier(); 108 void MemoryBarrier();
101 void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value); 109 void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value);
102 void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); 110 void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
103 void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
104 void Release_Store(volatile Atomic32* ptr, Atomic32 value); 111 void Release_Store(volatile Atomic32* ptr, Atomic32 value);
105 112
106 Atomic8 NoBarrier_Load(volatile const Atomic8* ptr); 113 Atomic8 NoBarrier_Load(volatile const Atomic8* ptr);
107 Atomic32 NoBarrier_Load(volatile const Atomic32* ptr); 114 Atomic32 NoBarrier_Load(volatile const Atomic32* ptr);
108 Atomic32 Acquire_Load(volatile const Atomic32* ptr); 115 Atomic32 Acquire_Load(volatile const Atomic32* ptr);
109 Atomic32 Release_Load(volatile const Atomic32* ptr);
110 116
111 // 64-bit atomic operations (only available on 64-bit processors). 117 // 64-bit atomic operations (only available on 64-bit processors).
112 #ifdef V8_HOST_ARCH_64_BIT 118 #ifdef V8_HOST_ARCH_64_BIT
113 Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, 119 Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
114 Atomic64 old_value, 120 Atomic64 old_value,
115 Atomic64 new_value); 121 Atomic64 new_value);
116 Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value); 122 Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value);
117 Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment); 123 Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
118 Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment); 124 Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment);
119 125
120 Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, 126 Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
121 Atomic64 old_value, 127 Atomic64 old_value,
122 Atomic64 new_value); 128 Atomic64 new_value);
123 Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, 129 Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
124 Atomic64 old_value, 130 Atomic64 old_value,
125 Atomic64 new_value); 131 Atomic64 new_value);
126 void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value); 132 void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value);
127 void Acquire_Store(volatile Atomic64* ptr, Atomic64 value);
128 void Release_Store(volatile Atomic64* ptr, Atomic64 value); 133 void Release_Store(volatile Atomic64* ptr, Atomic64 value);
129 Atomic64 NoBarrier_Load(volatile const Atomic64* ptr); 134 Atomic64 NoBarrier_Load(volatile const Atomic64* ptr);
130 Atomic64 Acquire_Load(volatile const Atomic64* ptr); 135 Atomic64 Acquire_Load(volatile const Atomic64* ptr);
131 Atomic64 Release_Load(volatile const Atomic64* ptr);
132 #endif // V8_HOST_ARCH_64_BIT 136 #endif // V8_HOST_ARCH_64_BIT
133 137
134 } // namespace base 138 } // namespace base
135 } // namespace v8 139 } // namespace v8
136 140
137 // Include our platform specific implementation. 141 #if defined(V8_OS_WIN)
138 #if defined(THREAD_SANITIZER) 142 // TODO(hpayer): The MSVC header includes windows.h, which other files end up
139 #include "src/base/atomicops_internals_tsan.h" 143 // relying on. Fix this as part of crbug.com/559247.
140 #elif defined(_MSC_VER) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
141 #include "src/base/atomicops_internals_x86_msvc.h" 144 #include "src/base/atomicops_internals_x86_msvc.h"
142 #elif defined(__APPLE__)
143 #include "src/base/atomicops_internals_mac.h"
144 #elif defined(__GNUC__) && V8_HOST_ARCH_ARM64
145 #include "src/base/atomicops_internals_arm64_gcc.h"
146 #elif defined(__GNUC__) && V8_HOST_ARCH_ARM
147 #include "src/base/atomicops_internals_arm_gcc.h"
148 #elif defined(__GNUC__) && V8_HOST_ARCH_PPC
149 #include "src/base/atomicops_internals_ppc_gcc.h"
150 #elif defined(__GNUC__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
151 #include "src/base/atomicops_internals_x86_gcc.h"
152 #elif defined(__GNUC__) && V8_HOST_ARCH_MIPS
153 #include "src/base/atomicops_internals_mips_gcc.h"
154 #elif defined(__GNUC__) && V8_HOST_ARCH_MIPS64
155 #include "src/base/atomicops_internals_mips64_gcc.h"
156 #elif defined(__GNUC__) && V8_HOST_ARCH_S390
157 #include "src/base/atomicops_internals_s390_gcc.h"
158 #else 145 #else
159 #error "Atomic operations are not supported on your platform" 146 #include "src/base/atomicops_internals_portable.h"
160 #endif 147 #endif
161 148
162 // On some platforms we need additional declarations to make 149 // On some platforms we need additional declarations to make
163 // AtomicWord compatible with our other Atomic* types. 150 // AtomicWord compatible with our other Atomic* types.
164 #if defined(__APPLE__) || defined(__OpenBSD__) || defined(V8_OS_AIX) 151 #if defined(V8_OS_MACOSX) || defined(V8_OS_OPENBSD) || defined(V8_OS_AIX)
165 #include "src/base/atomicops_internals_atomicword_compat.h" 152 #include "src/base/atomicops_internals_atomicword_compat.h"
166 #endif 153 #endif
167 154
168 #endif // V8_BASE_ATOMICOPS_H_ 155 #endif // V8_BASE_ATOMICOPS_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/base/atomicops_internals_arm64_gcc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698