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 RUNTIME_VM_ATOMIC_WIN_H_ | 5 #ifndef RUNTIME_VM_ATOMIC_WIN_H_ |
6 #define RUNTIME_VM_ATOMIC_WIN_H_ | 6 #define RUNTIME_VM_ATOMIC_WIN_H_ |
7 | 7 |
8 #if !defined RUNTIME_VM_ATOMIC_H_ | 8 #if !defined RUNTIME_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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 1; | 22 1; |
23 #elif defined(HOST_ARCH_IA32) | 23 #elif defined(HOST_ARCH_IA32) |
24 return static_cast<uintptr_t>( | 24 return static_cast<uintptr_t>( |
25 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - | 25 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - |
26 1; | 26 1; |
27 #else | 27 #else |
28 #error Unsupported host architecture. | 28 #error Unsupported host architecture. |
29 #endif | 29 #endif |
30 } | 30 } |
31 | 31 |
32 | |
33 inline intptr_t AtomicOperations::FetchAndIncrement(intptr_t* p) { | 32 inline intptr_t AtomicOperations::FetchAndIncrement(intptr_t* p) { |
34 #if defined(HOST_ARCH_X64) | 33 #if defined(HOST_ARCH_X64) |
35 return static_cast<intptr_t>( | 34 return static_cast<intptr_t>( |
36 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - | 35 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - |
37 1; | 36 1; |
38 #elif defined(HOST_ARCH_IA32) | 37 #elif defined(HOST_ARCH_IA32) |
39 return static_cast<intptr_t>( | 38 return static_cast<intptr_t>( |
40 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - | 39 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - |
41 1; | 40 1; |
42 #else | 41 #else |
43 #error Unsupported host architecture. | 42 #error Unsupported host architecture. |
44 #endif | 43 #endif |
45 } | 44 } |
46 | 45 |
47 | |
48 inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { | 46 inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { |
49 #if defined(HOST_ARCH_X64) | 47 #if defined(HOST_ARCH_X64) |
50 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), | 48 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), |
51 static_cast<LONGLONG>(value)); | 49 static_cast<LONGLONG>(value)); |
52 #elif defined(HOST_ARCH_IA32) | 50 #elif defined(HOST_ARCH_IA32) |
53 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(value)); | 51 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(value)); |
54 #else | 52 #else |
55 #error Unsupported host architecture. | 53 #error Unsupported host architecture. |
56 #endif | 54 #endif |
57 } | 55 } |
58 | 56 |
59 | |
60 inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) { | 57 inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) { |
61 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) | 58 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) |
62 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), | 59 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), |
63 static_cast<LONGLONG>(value)); | 60 static_cast<LONGLONG>(value)); |
64 #else | 61 #else |
65 #error Unsupported host architecture. | 62 #error Unsupported host architecture. |
66 #endif | 63 #endif |
67 } | 64 } |
68 | 65 |
69 | |
70 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { | 66 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { |
71 #if defined(HOST_ARCH_X64) | 67 #if defined(HOST_ARCH_X64) |
72 return static_cast<uintptr_t>( | 68 return static_cast<uintptr_t>( |
73 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + | 69 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + |
74 1; | 70 1; |
75 #elif defined(HOST_ARCH_IA32) | 71 #elif defined(HOST_ARCH_IA32) |
76 return static_cast<uintptr_t>( | 72 return static_cast<uintptr_t>( |
77 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + | 73 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + |
78 1; | 74 1; |
79 #else | 75 #else |
80 #error Unsupported host architecture. | 76 #error Unsupported host architecture. |
81 #endif | 77 #endif |
82 } | 78 } |
83 | 79 |
84 | |
85 inline intptr_t AtomicOperations::FetchAndDecrement(intptr_t* p) { | 80 inline intptr_t AtomicOperations::FetchAndDecrement(intptr_t* p) { |
86 #if defined(HOST_ARCH_X64) | 81 #if defined(HOST_ARCH_X64) |
87 return static_cast<intptr_t>( | 82 return static_cast<intptr_t>( |
88 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + | 83 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + |
89 1; | 84 1; |
90 #elif defined(HOST_ARCH_IA32) | 85 #elif defined(HOST_ARCH_IA32) |
91 return static_cast<intptr_t>( | 86 return static_cast<intptr_t>( |
92 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + | 87 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + |
93 1; | 88 1; |
94 #else | 89 #else |
95 #error Unsupported host architecture. | 90 #error Unsupported host architecture. |
96 #endif | 91 #endif |
97 } | 92 } |
98 | 93 |
99 | |
100 inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { | 94 inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { |
101 #if defined(HOST_ARCH_X64) | 95 #if defined(HOST_ARCH_X64) |
102 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), | 96 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), |
103 static_cast<LONGLONG>(-value)); | 97 static_cast<LONGLONG>(-value)); |
104 #elif defined(HOST_ARCH_IA32) | 98 #elif defined(HOST_ARCH_IA32) |
105 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(-value)); | 99 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(-value)); |
106 #else | 100 #else |
107 #error Unsupported host architecture. | 101 #error Unsupported host architecture. |
108 #endif | 102 #endif |
109 } | 103 } |
110 | 104 |
111 | |
112 #if !defined(USING_SIMULATOR) | 105 #if !defined(USING_SIMULATOR) |
113 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, | 106 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, |
114 uword old_value, | 107 uword old_value, |
115 uword new_value) { | 108 uword new_value) { |
116 #if defined(HOST_ARCH_X64) | 109 #if defined(HOST_ARCH_X64) |
117 return static_cast<uword>(InterlockedCompareExchange64( | 110 return static_cast<uword>(InterlockedCompareExchange64( |
118 reinterpret_cast<LONGLONG*>(ptr), static_cast<LONGLONG>(new_value), | 111 reinterpret_cast<LONGLONG*>(ptr), static_cast<LONGLONG>(new_value), |
119 static_cast<LONGLONG>(old_value))); | 112 static_cast<LONGLONG>(old_value))); |
120 #elif defined(HOST_ARCH_IA32) | 113 #elif defined(HOST_ARCH_IA32) |
121 return static_cast<uword>(InterlockedCompareExchange( | 114 return static_cast<uword>(InterlockedCompareExchange( |
(...skipping 12 matching lines...) Expand all Loading... |
134 static_cast<LONG>(old_value))); | 127 static_cast<LONG>(old_value))); |
135 #else | 128 #else |
136 #error Unsupported host architecture. | 129 #error Unsupported host architecture. |
137 #endif | 130 #endif |
138 } | 131 } |
139 #endif // !defined(USING_SIMULATOR) | 132 #endif // !defined(USING_SIMULATOR) |
140 | 133 |
141 } // namespace dart | 134 } // namespace dart |
142 | 135 |
143 #endif // RUNTIME_VM_ATOMIC_WIN_H_ | 136 #endif // RUNTIME_VM_ATOMIC_WIN_H_ |
OLD | NEW |