| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // This file is an internal atomic implementation, use atomicops.h instead. |
| 29 |
| 30 #ifndef V8_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| 31 #define V8_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| 32 |
| 33 #include "win32-headers.h" |
| 34 |
| 35 namespace v8 { |
| 36 namespace internal { |
| 37 |
| 38 inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, |
| 39 Atomic32 old_value, |
| 40 Atomic32 new_value) { |
| 41 LONG result = InterlockedCompareExchange( |
| 42 reinterpret_cast<volatile LONG*>(ptr), |
| 43 static_cast<LONG>(new_value), |
| 44 static_cast<LONG>(old_value)); |
| 45 return static_cast<Atomic32>(result); |
| 46 } |
| 47 |
| 48 inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, |
| 49 Atomic32 new_value) { |
| 50 LONG result = InterlockedExchange( |
| 51 reinterpret_cast<volatile LONG*>(ptr), |
| 52 static_cast<LONG>(new_value)); |
| 53 return static_cast<Atomic32>(result); |
| 54 } |
| 55 |
| 56 inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, |
| 57 Atomic32 increment) { |
| 58 return InterlockedExchangeAdd( |
| 59 reinterpret_cast<volatile LONG*>(ptr), |
| 60 static_cast<LONG>(increment)) + increment; |
| 61 } |
| 62 |
| 63 inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, |
| 64 Atomic32 increment) { |
| 65 return Barrier_AtomicIncrement(ptr, increment); |
| 66 } |
| 67 |
| 68 #if !(defined(_MSC_VER) && _MSC_VER >= 1400) |
| 69 #error "We require at least vs2005 for MemoryBarrier" |
| 70 #endif |
| 71 inline void MemoryBarrier() { |
| 72 // We use MemoryBarrier from WinNT.h |
| 73 ::MemoryBarrier(); |
| 74 } |
| 75 |
| 76 inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, |
| 77 Atomic32 old_value, |
| 78 Atomic32 new_value) { |
| 79 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 80 } |
| 81 |
| 82 inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, |
| 83 Atomic32 old_value, |
| 84 Atomic32 new_value) { |
| 85 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 86 } |
| 87 |
| 88 inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { |
| 89 *ptr = value; |
| 90 } |
| 91 |
| 92 inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { |
| 93 NoBarrier_AtomicExchange(ptr, value); |
| 94 // acts as a barrier in this implementation |
| 95 } |
| 96 |
| 97 inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { |
| 98 *ptr = value; // works w/o barrier for current Intel chips as of June 2005 |
| 99 // See comments in Atomic64 version of Release_Store() below. |
| 100 } |
| 101 |
| 102 inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { |
| 103 return *ptr; |
| 104 } |
| 105 |
| 106 inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { |
| 107 Atomic32 value = *ptr; |
| 108 return value; |
| 109 } |
| 110 |
| 111 inline Atomic32 Release_Load(volatile const Atomic32* ptr) { |
| 112 MemoryBarrier(); |
| 113 return *ptr; |
| 114 } |
| 115 |
| 116 #if defined(_WIN64) |
| 117 |
| 118 // 64-bit low-level operations on 64-bit platform. |
| 119 |
| 120 STATIC_ASSERT(sizeof(Atomic64) == sizeof(PVOID)); |
| 121 |
| 122 inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, |
| 123 Atomic64 old_value, |
| 124 Atomic64 new_value) { |
| 125 PVOID result = InterlockedCompareExchangePointer( |
| 126 reinterpret_cast<volatile PVOID*>(ptr), |
| 127 reinterpret_cast<PVOID>(new_value), reinterpret_cast<PVOID>(old_value)); |
| 128 return reinterpret_cast<Atomic64>(result); |
| 129 } |
| 130 |
| 131 inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, |
| 132 Atomic64 new_value) { |
| 133 PVOID result = InterlockedExchangePointer( |
| 134 reinterpret_cast<volatile PVOID*>(ptr), |
| 135 reinterpret_cast<PVOID>(new_value)); |
| 136 return reinterpret_cast<Atomic64>(result); |
| 137 } |
| 138 |
| 139 inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, |
| 140 Atomic64 increment) { |
| 141 return InterlockedExchangeAdd64( |
| 142 reinterpret_cast<volatile LONGLONG*>(ptr), |
| 143 static_cast<LONGLONG>(increment)) + increment; |
| 144 } |
| 145 |
| 146 inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, |
| 147 Atomic64 increment) { |
| 148 return Barrier_AtomicIncrement(ptr, increment); |
| 149 } |
| 150 |
| 151 inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { |
| 152 *ptr = value; |
| 153 } |
| 154 |
| 155 inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { |
| 156 NoBarrier_AtomicExchange(ptr, value); |
| 157 // acts as a barrier in this implementation |
| 158 } |
| 159 |
| 160 inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { |
| 161 *ptr = value; // works w/o barrier for current Intel chips as of June 2005 |
| 162 |
| 163 // When new chips come out, check: |
| 164 // IA-32 Intel Architecture Software Developer's Manual, Volume 3: |
| 165 // System Programming Guide, Chatper 7: Multiple-processor management, |
| 166 // Section 7.2, Memory Ordering. |
| 167 // Last seen at: |
| 168 // http://developer.intel.com/design/pentium4/manuals/index_new.htm |
| 169 } |
| 170 |
| 171 inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { |
| 172 return *ptr; |
| 173 } |
| 174 |
| 175 inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { |
| 176 Atomic64 value = *ptr; |
| 177 return value; |
| 178 } |
| 179 |
| 180 inline Atomic64 Release_Load(volatile const Atomic64* ptr) { |
| 181 MemoryBarrier(); |
| 182 return *ptr; |
| 183 } |
| 184 |
| 185 inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, |
| 186 Atomic64 old_value, |
| 187 Atomic64 new_value) { |
| 188 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 189 } |
| 190 |
| 191 inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, |
| 192 Atomic64 old_value, |
| 193 Atomic64 new_value) { |
| 194 return NoBarrier_CompareAndSwap(ptr, old_value, new_value); |
| 195 } |
| 196 |
| 197 |
| 198 #endif // defined(_WIN64) |
| 199 |
| 200 } } // namespace v8::internal |
| 201 |
| 202 #endif // V8_ATOMICOPS_INTERNALS_X86_MSVC_H_ |
| OLD | NEW |