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

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

Issue 2912773002: Rename "NoBarrier" memory operations to "Relaxed". (Closed)
Patch Set: comment Created 3 years, 6 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 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 // This file is an internal atomic implementation, use base/atomicops.h instead. 5 // This file is an internal atomic implementation, use base/atomicops.h instead.
6 6
7 #ifndef V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ 7 #ifndef V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
8 #define V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ 8 #define V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
9 9
10 #include "src/base/macros.h" 10 #include "src/base/macros.h"
11 #include "src/base/win32-headers.h" 11 #include "src/base/win32-headers.h"
12 12
13 #if defined(V8_HOST_ARCH_64_BIT) 13 #if defined(V8_HOST_ARCH_64_BIT)
14 // windows.h #defines this (only on x64). This causes problems because the 14 // windows.h #defines this (only on x64). This causes problems because the
15 // public API also uses MemoryBarrier at the public name for this fence. So, on 15 // public API also uses MemoryBarrier at the public name for this fence. So, on
16 // X64, undef it, and call its documented 16 // X64, undef it, and call its documented
17 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx) 17 // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684208.aspx)
18 // implementation directly. 18 // implementation directly.
19 #undef MemoryBarrier 19 #undef MemoryBarrier
20 #endif 20 #endif
21 21
22 namespace v8 { 22 namespace v8 {
23 namespace base { 23 namespace base {
24 24
25 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, 25 inline Atomic32 Relaxed_CompareAndSwap(volatile Atomic32* ptr,
26 Atomic32 old_value, 26 Atomic32 old_value, Atomic32 new_value) {
27 Atomic32 new_value) {
28 LONG result = InterlockedCompareExchange( 27 LONG result = InterlockedCompareExchange(
29 reinterpret_cast<volatile LONG*>(ptr), static_cast<LONG>(new_value), 28 reinterpret_cast<volatile LONG*>(ptr), static_cast<LONG>(new_value),
30 static_cast<LONG>(old_value)); 29 static_cast<LONG>(old_value));
31 return static_cast<Atomic32>(result); 30 return static_cast<Atomic32>(result);
32 } 31 }
33 32
34 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, 33 inline Atomic32 Relaxed_AtomicExchange(volatile Atomic32* ptr,
35 Atomic32 new_value) { 34 Atomic32 new_value) {
36 LONG result = InterlockedExchange(reinterpret_cast<volatile LONG*>(ptr), 35 LONG result = InterlockedExchange(reinterpret_cast<volatile LONG*>(ptr),
37 static_cast<LONG>(new_value)); 36 static_cast<LONG>(new_value));
38 return static_cast<Atomic32>(result); 37 return static_cast<Atomic32>(result);
39 } 38 }
40 39
41 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, 40 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
42 Atomic32 increment) { 41 Atomic32 increment) {
43 return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), 42 return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr),
44 static_cast<LONG>(increment)) + 43 static_cast<LONG>(increment)) +
45 increment; 44 increment;
46 } 45 }
47 46
48 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, 47 inline Atomic32 Relaxed_AtomicIncrement(volatile Atomic32* ptr,
49 Atomic32 increment) { 48 Atomic32 increment) {
50 return Barrier_AtomicIncrement(ptr, increment); 49 return Barrier_AtomicIncrement(ptr, increment);
51 } 50 }
52 51
53 inline void MemoryBarrier() { 52 inline void MemoryBarrier() {
54 #if defined(V8_HOST_ARCH_64_BIT) 53 #if defined(V8_HOST_ARCH_64_BIT)
55 // See #undef and note at the top of this file. 54 // See #undef and note at the top of this file.
56 __faststorefence(); 55 __faststorefence();
57 #else 56 #else
58 // We use MemoryBarrier from WinNT.h 57 // We use MemoryBarrier from WinNT.h
59 ::MemoryBarrier(); 58 ::MemoryBarrier();
60 #endif 59 #endif
61 } 60 }
62 61
63 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, 62 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
64 Atomic32 old_value, 63 Atomic32 old_value,
65 Atomic32 new_value) { 64 Atomic32 new_value) {
66 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 65 return Relaxed_CompareAndSwap(ptr, old_value, new_value);
67 } 66 }
68 67
69 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, 68 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
70 Atomic32 old_value, 69 Atomic32 old_value,
71 Atomic32 new_value) { 70 Atomic32 new_value) {
72 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 71 return Relaxed_CompareAndSwap(ptr, old_value, new_value);
73 } 72 }
74 73
75 inline void NoBarrier_Store(volatile Atomic8* ptr, Atomic8 value) { 74 inline void Relaxed_Store(volatile Atomic8* ptr, Atomic8 value) {
76 *ptr = value; 75 *ptr = value;
77 } 76 }
78 77
79 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { 78 inline void Relaxed_Store(volatile Atomic32* ptr, Atomic32 value) {
80 *ptr = value; 79 *ptr = value;
81 } 80 }
82 81
83 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { 82 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
84 *ptr = value; // works w/o barrier for current Intel chips as of June 2005 83 *ptr = value; // works w/o barrier for current Intel chips as of June 2005
85 // See comments in Atomic64 version of Release_Store() below. 84 // See comments in Atomic64 version of Release_Store() below.
86 } 85 }
87 86
88 inline Atomic8 NoBarrier_Load(volatile const Atomic8* ptr) { 87 inline Atomic8 Relaxed_Load(volatile const Atomic8* ptr) { return *ptr; }
89 return *ptr;
90 }
91 88
92 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { 89 inline Atomic32 Relaxed_Load(volatile const Atomic32* ptr) { return *ptr; }
93 return *ptr;
94 }
95 90
96 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { 91 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
97 Atomic32 value = *ptr; 92 Atomic32 value = *ptr;
98 return value; 93 return value;
99 } 94 }
100 95
101 #if defined(_WIN64) 96 #if defined(_WIN64)
102 97
103 // 64-bit low-level operations on 64-bit platform. 98 // 64-bit low-level operations on 64-bit platform.
104 99
105 static_assert(sizeof(Atomic64) == sizeof(PVOID), "atomic word is atomic"); 100 static_assert(sizeof(Atomic64) == sizeof(PVOID), "atomic word is atomic");
106 101
107 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, 102 inline Atomic64 Relaxed_CompareAndSwap(volatile Atomic64* ptr,
108 Atomic64 old_value, 103 Atomic64 old_value, Atomic64 new_value) {
109 Atomic64 new_value) {
110 PVOID result = InterlockedCompareExchangePointer( 104 PVOID result = InterlockedCompareExchangePointer(
111 reinterpret_cast<volatile PVOID*>(ptr), 105 reinterpret_cast<volatile PVOID*>(ptr),
112 reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value)); 106 reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value));
113 return reinterpret_cast<Atomic64>(result); 107 return reinterpret_cast<Atomic64>(result);
114 } 108 }
115 109
116 inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, 110 inline Atomic64 Relaxed_AtomicExchange(volatile Atomic64* ptr,
117 Atomic64 new_value) { 111 Atomic64 new_value) {
118 PVOID result = InterlockedExchangePointer( 112 PVOID result = InterlockedExchangePointer(
119 reinterpret_cast<volatile PVOID*>(ptr), 113 reinterpret_cast<volatile PVOID*>(ptr),
120 reinterpret_cast<PVOID>(new_value)); 114 reinterpret_cast<PVOID>(new_value));
121 return reinterpret_cast<Atomic64>(result); 115 return reinterpret_cast<Atomic64>(result);
122 } 116 }
123 117
124 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, 118 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
125 Atomic64 increment) { 119 Atomic64 increment) {
126 return InterlockedExchangeAdd64( 120 return InterlockedExchangeAdd64(
127 reinterpret_cast<volatile LONGLONG*>(ptr), 121 reinterpret_cast<volatile LONGLONG*>(ptr),
128 static_cast<LONGLONG>(increment)) + increment; 122 static_cast<LONGLONG>(increment)) + increment;
129 } 123 }
130 124
131 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, 125 inline Atomic64 Relaxed_AtomicIncrement(volatile Atomic64* ptr,
132 Atomic64 increment) { 126 Atomic64 increment) {
133 return Barrier_AtomicIncrement(ptr, increment); 127 return Barrier_AtomicIncrement(ptr, increment);
134 } 128 }
135 129
136 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { 130 inline void Relaxed_Store(volatile Atomic64* ptr, Atomic64 value) {
137 *ptr = value; 131 *ptr = value;
138 } 132 }
139 133
140 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { 134 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
141 *ptr = value; // works w/o barrier for current Intel chips as of June 2005 135 *ptr = value; // works w/o barrier for current Intel chips as of June 2005
142 136
143 // When new chips come out, check: 137 // When new chips come out, check:
144 // IA-32 Intel Architecture Software Developer's Manual, Volume 3: 138 // IA-32 Intel Architecture Software Developer's Manual, Volume 3:
145 // System Programming Guide, Chatper 7: Multiple-processor management, 139 // System Programming Guide, Chatper 7: Multiple-processor management,
146 // Section 7.2, Memory Ordering. 140 // Section 7.2, Memory Ordering.
147 // Last seen at: 141 // Last seen at:
148 // http://developer.intel.com/design/pentium4/manuals/index_new.htm 142 // http://developer.intel.com/design/pentium4/manuals/index_new.htm
149 } 143 }
150 144
151 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { 145 inline Atomic64 Relaxed_Load(volatile const Atomic64* ptr) { return *ptr; }
152 return *ptr;
153 }
154 146
155 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { 147 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
156 Atomic64 value = *ptr; 148 Atomic64 value = *ptr;
157 return value; 149 return value;
158 } 150 }
159 151
160 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, 152 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
161 Atomic64 old_value, 153 Atomic64 old_value,
162 Atomic64 new_value) { 154 Atomic64 new_value) {
163 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 155 return Relaxed_CompareAndSwap(ptr, old_value, new_value);
164 } 156 }
165 157
166 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, 158 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
167 Atomic64 old_value, 159 Atomic64 old_value,
168 Atomic64 new_value) { 160 Atomic64 new_value) {
169 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); 161 return Relaxed_CompareAndSwap(ptr, old_value, new_value);
170 } 162 }
171 163
172 164
173 #endif // defined(_WIN64) 165 #endif // defined(_WIN64)
174 166
175 } // namespace base 167 } // namespace base
176 } // namespace v8 168 } // namespace v8
177 169
178 #endif // V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ 170 #endif // V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
OLDNEW
« no previous file with comments | « src/base/atomicops_internals_portable.h ('k') | src/compiler-dispatcher/optimizing-compile-dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698