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

Side by Side Diff: runtime/vm/atomic_win.h

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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
« no previous file with comments | « runtime/vm/atomic_test.cc ('k') | runtime/vm/base_isolate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(HOST_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))) -
22 1;
22 #elif defined(HOST_ARCH_IA32) 23 #elif defined(HOST_ARCH_IA32)
23 return static_cast<uintptr_t>( 24 return static_cast<uintptr_t>(
24 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - 1; 25 InterlockedIncrement(reinterpret_cast<LONG*>(p))) -
26 1;
25 #else 27 #else
26 #error Unsupported host architecture. 28 #error Unsupported host architecture.
27 #endif 29 #endif
28 } 30 }
29 31
30 32
31 inline intptr_t AtomicOperations::FetchAndIncrement(intptr_t* p) { 33 inline intptr_t AtomicOperations::FetchAndIncrement(intptr_t* p) {
32 #if defined(HOST_ARCH_X64) 34 #if defined(HOST_ARCH_X64)
33 return static_cast<intptr_t>( 35 return static_cast<intptr_t>(
34 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - 1; 36 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) -
37 1;
35 #elif defined(HOST_ARCH_IA32) 38 #elif defined(HOST_ARCH_IA32)
36 return static_cast<intptr_t>( 39 return static_cast<intptr_t>(
37 InterlockedIncrement(reinterpret_cast<LONG*>(p))) - 1; 40 InterlockedIncrement(reinterpret_cast<LONG*>(p))) -
41 1;
38 #else 42 #else
39 #error Unsupported host architecture. 43 #error Unsupported host architecture.
40 #endif 44 #endif
41 } 45 }
42 46
43 47
44 inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) { 48 inline void AtomicOperations::IncrementBy(intptr_t* p, intptr_t value) {
45 #if defined(HOST_ARCH_X64) 49 #if defined(HOST_ARCH_X64)
46 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), 50 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
47 static_cast<LONGLONG>(value)); 51 static_cast<LONGLONG>(value));
48 #elif defined(HOST_ARCH_IA32) 52 #elif defined(HOST_ARCH_IA32)
49 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), 53 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(value));
50 static_cast<LONG>(value));
51 #else 54 #else
52 #error Unsupported host architecture. 55 #error Unsupported host architecture.
53 #endif 56 #endif
54 } 57 }
55 58
56 59
57 inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) { 60 inline void AtomicOperations::IncrementInt64By(int64_t* p, int64_t value) {
58 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) 61 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
59 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), 62 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
60 static_cast<LONGLONG>(value)); 63 static_cast<LONGLONG>(value));
61 #else 64 #else
62 #error Unsupported host architecture. 65 #error Unsupported host architecture.
63 #endif 66 #endif
64 } 67 }
65 68
66 69
67 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { 70 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) {
68 #if defined(HOST_ARCH_X64) 71 #if defined(HOST_ARCH_X64)
69 return static_cast<uintptr_t>( 72 return static_cast<uintptr_t>(
70 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + 1; 73 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) +
74 1;
71 #elif defined(HOST_ARCH_IA32) 75 #elif defined(HOST_ARCH_IA32)
72 return static_cast<uintptr_t>( 76 return static_cast<uintptr_t>(
73 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + 1; 77 InterlockedDecrement(reinterpret_cast<LONG*>(p))) +
78 1;
74 #else 79 #else
75 #error Unsupported host architecture. 80 #error Unsupported host architecture.
76 #endif 81 #endif
77 } 82 }
78 83
79 84
80 inline intptr_t AtomicOperations::FetchAndDecrement(intptr_t* p) { 85 inline intptr_t AtomicOperations::FetchAndDecrement(intptr_t* p) {
81 #if defined(HOST_ARCH_X64) 86 #if defined(HOST_ARCH_X64)
82 return static_cast<intptr_t>( 87 return static_cast<intptr_t>(
83 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + 1; 88 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) +
89 1;
84 #elif defined(HOST_ARCH_IA32) 90 #elif defined(HOST_ARCH_IA32)
85 return static_cast<intptr_t>( 91 return static_cast<intptr_t>(
86 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + 1; 92 InterlockedDecrement(reinterpret_cast<LONG*>(p))) +
93 1;
87 #else 94 #else
88 #error Unsupported host architecture. 95 #error Unsupported host architecture.
89 #endif 96 #endif
90 } 97 }
91 98
92 99
93 inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) { 100 inline void AtomicOperations::DecrementBy(intptr_t* p, intptr_t value) {
94 #if defined(HOST_ARCH_X64) 101 #if defined(HOST_ARCH_X64)
95 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p), 102 InterlockedExchangeAdd64(reinterpret_cast<LONGLONG*>(p),
96 static_cast<LONGLONG>(-value)); 103 static_cast<LONGLONG>(-value));
97 #elif defined(HOST_ARCH_IA32) 104 #elif defined(HOST_ARCH_IA32)
98 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), 105 InterlockedExchangeAdd(reinterpret_cast<LONG*>(p), static_cast<LONG>(-value));
99 static_cast<LONG>(-value));
100 #else 106 #else
101 #error Unsupported host architecture. 107 #error Unsupported host architecture.
102 #endif 108 #endif
103 } 109 }
104 110
105 111
106 #if !defined(USING_SIMULATOR) 112 #if !defined(USING_SIMULATOR)
107 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, 113 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr,
108 uword old_value, 114 uword old_value,
109 uword new_value) { 115 uword new_value) {
110 #if defined(HOST_ARCH_X64) 116 #if defined(HOST_ARCH_X64)
111 return static_cast<uword>( 117 return static_cast<uword>(InterlockedCompareExchange64(
112 InterlockedCompareExchange64(reinterpret_cast<LONGLONG*>(ptr), 118 reinterpret_cast<LONGLONG*>(ptr), static_cast<LONGLONG>(new_value),
113 static_cast<LONGLONG>(new_value), 119 static_cast<LONGLONG>(old_value)));
114 static_cast<LONGLONG>(old_value)));
115 #elif defined(HOST_ARCH_IA32) 120 #elif defined(HOST_ARCH_IA32)
116 return static_cast<uword>( 121 return static_cast<uword>(InterlockedCompareExchange(
117 InterlockedCompareExchange(reinterpret_cast<LONG*>(ptr), 122 reinterpret_cast<LONG*>(ptr), static_cast<LONG>(new_value),
118 static_cast<LONG>(new_value), 123 static_cast<LONG>(old_value)));
119 static_cast<LONG>(old_value)));
120 #else 124 #else
121 #error Unsupported host architecture. 125 #error Unsupported host architecture.
122 #endif 126 #endif
123 } 127 }
124 inline uint32_t AtomicOperations::CompareAndSwapUint32(uint32_t* ptr, 128 inline uint32_t AtomicOperations::CompareAndSwapUint32(uint32_t* ptr,
125 uint32_t old_value, 129 uint32_t old_value,
126 uint32_t new_value) { 130 uint32_t new_value) {
127 #if (defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32)) 131 #if (defined(HOST_ARCH_X64) || defined(HOST_ARCH_IA32))
128 return static_cast<uint32_t>( 132 return static_cast<uint32_t>(InterlockedCompareExchange(
129 InterlockedCompareExchange(reinterpret_cast<LONG*>(ptr), 133 reinterpret_cast<LONG*>(ptr), static_cast<LONG>(new_value),
130 static_cast<LONG>(new_value), 134 static_cast<LONG>(old_value)));
131 static_cast<LONG>(old_value)));
132 #else 135 #else
133 #error Unsupported host architecture. 136 #error Unsupported host architecture.
134 #endif 137 #endif
135 } 138 }
136 #endif // !defined(USING_SIMULATOR) 139 #endif // !defined(USING_SIMULATOR)
137 140
138 } // namespace dart 141 } // namespace dart
139 142
140 #endif // RUNTIME_VM_ATOMIC_WIN_H_ 143 #endif // RUNTIME_VM_ATOMIC_WIN_H_
OLDNEW
« no previous file with comments | « runtime/vm/atomic_test.cc ('k') | runtime/vm/base_isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698