OLD | NEW |
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 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 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
26 Atomic32 old_value, | 26 Atomic32 old_value, |
27 Atomic32 new_value) { | 27 Atomic32 new_value) { |
28 LONG result = InterlockedCompareExchange( | 28 LONG result = InterlockedCompareExchange( |
29 reinterpret_cast<volatile LONG*>(ptr), | 29 reinterpret_cast<volatile LONG*>(ptr), static_cast<LONG>(new_value), |
30 static_cast<LONG>(new_value), | |
31 static_cast<LONG>(old_value)); | 30 static_cast<LONG>(old_value)); |
32 return static_cast<Atomic32>(result); | 31 return static_cast<Atomic32>(result); |
33 } | 32 } |
34 | 33 |
35 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, | 34 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
36 Atomic32 new_value) { | 35 Atomic32 new_value) { |
37 LONG result = InterlockedExchange( | 36 LONG result = InterlockedExchange(reinterpret_cast<volatile LONG*>(ptr), |
38 reinterpret_cast<volatile LONG*>(ptr), | 37 static_cast<LONG>(new_value)); |
39 static_cast<LONG>(new_value)); | |
40 return static_cast<Atomic32>(result); | 38 return static_cast<Atomic32>(result); |
41 } | 39 } |
42 | 40 |
43 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, | 41 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
44 Atomic32 increment) { | 42 Atomic32 increment) { |
45 return InterlockedExchangeAdd( | 43 return InterlockedExchangeAdd(reinterpret_cast<volatile LONG*>(ptr), |
46 reinterpret_cast<volatile LONG*>(ptr), | 44 static_cast<LONG>(increment)) + |
47 static_cast<LONG>(increment)) + increment; | 45 increment; |
48 } | 46 } |
49 | 47 |
50 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, | 48 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
51 Atomic32 increment) { | 49 Atomic32 increment) { |
52 return Barrier_AtomicIncrement(ptr, increment); | 50 return Barrier_AtomicIncrement(ptr, increment); |
53 } | 51 } |
54 | 52 |
55 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) | |
56 #error "We require at least vs2005 for MemoryBarrier" | |
57 #endif | |
58 inline void MemoryBarrier() { | 53 inline void MemoryBarrier() { |
59 #if defined(V8_HOST_ARCH_64_BIT) | 54 #if defined(V8_HOST_ARCH_64_BIT) |
60 // See #undef and note at the top of this file. | 55 // See #undef and note at the top of this file. |
61 __faststorefence(); | 56 __faststorefence(); |
62 #else | 57 #else |
63 // We use MemoryBarrier from WinNT.h | 58 // We use MemoryBarrier from WinNT.h |
64 ::MemoryBarrier(); | 59 ::MemoryBarrier(); |
65 #endif | 60 #endif |
66 } | 61 } |
67 | 62 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 105 |
111 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { | 106 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { |
112 MemoryBarrier(); | 107 MemoryBarrier(); |
113 return *ptr; | 108 return *ptr; |
114 } | 109 } |
115 | 110 |
116 #if defined(_WIN64) | 111 #if defined(_WIN64) |
117 | 112 |
118 // 64-bit low-level operations on 64-bit platform. | 113 // 64-bit low-level operations on 64-bit platform. |
119 | 114 |
120 STATIC_ASSERT(sizeof(Atomic64) == sizeof(PVOID)); | 115 static_assert(sizeof(Atomic64) == sizeof(PVOID), "atomic word is atomic"); |
121 | 116 |
122 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, | 117 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, |
123 Atomic64 old_value, | 118 Atomic64 old_value, |
124 Atomic64 new_value) { | 119 Atomic64 new_value) { |
125 PVOID result = InterlockedCompareExchangePointer( | 120 PVOID result = InterlockedCompareExchangePointer( |
126 reinterpret_cast<volatile PVOID*>(ptr), | 121 reinterpret_cast<volatile PVOID*>(ptr), |
127 reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value)); | 122 reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value)); |
128 return reinterpret_cast<Atomic64>(result); | 123 return reinterpret_cast<Atomic64>(result); |
129 } | 124 } |
130 | 125 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); | 189 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
195 } | 190 } |
196 | 191 |
197 | 192 |
198 #endif // defined(_WIN64) | 193 #endif // defined(_WIN64) |
199 | 194 |
200 } // namespace base | 195 } // namespace base |
201 } // namespace v8 | 196 } // namespace v8 |
202 | 197 |
203 #endif // V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ | 198 #endif // V8_BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
OLD | NEW |