OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_ATOMIC_WIN_H_ | 5 #ifndef VM_ATOMIC_WIN_H_ |
6 #define VM_ATOMIC_WIN_H_ | 6 #define VM_ATOMIC_WIN_H_ |
7 | 7 |
8 #if !defined VM_ATOMIC_H_ | 8 #if !defined VM_ATOMIC_H_ |
9 #error Do not include atomic_win.h directly. Use atomic.h instead. | 9 #error Do not include atomic_win.h directly. Use atomic.h instead. |
10 #endif | 10 #endif |
11 | 11 |
12 #if !defined(TARGET_OS_WINDOWS) | 12 #if !defined(TARGET_OS_WINDOWS) |
13 #error This file should only be included on Windows builds. | 13 #error This file should only be included on Windows builds. |
14 #endif | 14 #endif |
15 | 15 |
16 namespace dart { | 16 namespace dart { |
17 | 17 |
18 inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { | 18 inline uintptr_t AtomicOperations::FetchAndIncrement(uintptr_t* p) { |
19 #if defined(TARGET_ARCH_X64) | 19 #if defined(HOST_ARCH_X64) |
20 return static_cast<uintptr_t>( | 20 return static_cast<uintptr_t>( |
21 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - 1; | 21 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - 1; |
22 #elif defined(TARGET_ARCH_IA32) | 22 #elif defined(HOST_ARCH_IA32) |
23 return static_cast<uintptr_t>( | 23 return static_cast<uintptr_t>( |
24 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - 1; | 24 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - 1; |
25 #else | 25 #else |
26 UNIMPLEMENTED(); | 26 #error Unsupported host architecture. |
27 #endif | 27 #endif |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 inline intptr_t AtomicOperations::FetchAndAdd(intptr_t* p, intptr_t delta) { | 31 inline intptr_t AtomicOperations::FetchAndAdd(intptr_t* p, intptr_t delta) { |
32 #if defined(TARGET_ARCH_X64) | 32 #if defined(HOST_ARCH_X64) |
33 return static_cast<intptr_t>( | 33 return static_cast<intptr_t>( |
34 InterlockedAdd64(reinterpret_cast<LONGLONG*>(p), delta)) - delta; | 34 InterlockedAdd64(reinterpret_cast<LONGLONG*>(p), delta)) - delta; |
35 #elif defined(TARGET_ARCH_IA32) | 35 #elif defined(HOST_ARCH_IA32) |
36 return static_cast<intptr_t>( | 36 return static_cast<intptr_t>( |
37 InterlockedAdd(reinterpret_cast<LONG*>(p), delta)) - delta; | 37 InterlockedAdd(reinterpret_cast<LONG*>(p), delta)) - delta; |
38 #else | 38 #else |
39 UNIMPLEMENTED(); | 39 #error Unsupported host architecture. |
40 #endif | 40 #endif |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 #if !defined(USING_SIMULATOR) | 44 #if !defined(USING_SIMULATOR) |
45 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, | 45 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, |
46 uword old_value, | 46 uword old_value, |
47 uword new_value) { | 47 uword new_value) { |
48 #if defined(TARGET_ARCH_X64) | 48 #if defined(HOST_ARCH_X64) |
49 return static_cast<uword>( | 49 return static_cast<uword>( |
50 InterlockedCompareExchange64(reinterpret_cast<LONGLONG*>(ptr), | 50 InterlockedCompareExchange64(reinterpret_cast<LONGLONG*>(ptr), |
51 static_cast<LONGLONG>(new_value), | 51 static_cast<LONGLONG>(new_value), |
52 static_cast<LONGLONG>(old_value))); | 52 static_cast<LONGLONG>(old_value))); |
53 #elif defined(TARGET_ARCH_IA32) | 53 #elif defined(HOST_ARCH_IA32) |
54 return static_cast<uword>( | 54 return static_cast<uword>( |
55 InterlockedCompareExchange(reinterpret_cast<LONG*>(ptr), | 55 InterlockedCompareExchange(reinterpret_cast<LONG*>(ptr), |
56 static_cast<LONG>(new_value), | 56 static_cast<LONG>(new_value), |
57 static_cast<LONG>(old_value))); | 57 static_cast<LONG>(old_value))); |
58 #else | 58 #else |
59 UNIMPLEMENTED(); | 59 #error Unsupported host architecture. |
60 #endif | 60 #endif |
61 } | 61 } |
62 #endif // !defined(USING_SIMULATOR) | 62 #endif // !defined(USING_SIMULATOR) |
63 | 63 |
64 } // namespace dart | 64 } // namespace dart |
65 | 65 |
66 #endif // VM_ATOMIC_WIN_H_ | 66 #endif // VM_ATOMIC_WIN_H_ |
OLD | NEW |