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

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

Issue 1580813003: Use atomic operations to increment/decrement memory usage counts as multiple threads could be alloc… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review Created 4 years, 11 months 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
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 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
(...skipping 10 matching lines...) Expand all
21 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - 1; 21 InterlockedIncrement64(reinterpret_cast<LONGLONG*>(p))) - 1;
22 #elif defined(HOST_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 #error Unsupported host architecture. 26 #error Unsupported host architecture.
27 #endif 27 #endif
28 } 28 }
29 29
30 30
31 inline intptr_t AtomicOperations::FetchAndIncrementBy(intptr_t* p,
32 intptr_t value) {
33 #if defined(HOST_ARCH_X64)
34 return static_cast<intptr_t>(
35 InterlockedAdd64(reinterpret_cast<LONGLONG*>(p),
36 static_cast<LONGLONG>(value))) - value;
37 #elif defined(HOST_ARCH_IA32)
38 return static_cast<intptr_t>(
39 InterlockedAdd(reinterpret_cast<LONG*>(p),
40 static_cast<LONGLONG>(value))) - value;
41 #else
42 #error Unsupported host architecture.
43 #endif
44 }
45
46
31 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) { 47 inline uintptr_t AtomicOperations::FetchAndDecrement(uintptr_t* p) {
32 #if defined(HOST_ARCH_X64) 48 #if defined(HOST_ARCH_X64)
33 return static_cast<uintptr_t>( 49 return static_cast<uintptr_t>(
34 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + 1; 50 InterlockedDecrement64(reinterpret_cast<LONGLONG*>(p))) + 1;
35 #elif defined(HOST_ARCH_IA32) 51 #elif defined(HOST_ARCH_IA32)
36 return static_cast<uintptr_t>( 52 return static_cast<uintptr_t>(
37 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + 1; 53 InterlockedDecrement(reinterpret_cast<LONG*>(p))) + 1;
38 #else 54 #else
39 #error Unsupported host architecture. 55 #error Unsupported host architecture.
40 #endif 56 #endif
41 } 57 }
42 58
43 59
60 inline intptr_t AtomicOperations::FetchAndDecrementBy(intptr_t* p,
61 intptr_t value) {
62 #if defined(HOST_ARCH_X64)
63 return static_cast<intptr_t>(
64 InterlockedAdd64(reinterpret_cast<LONGLONG*>(p),
65 static_cast<LONGLONG>(-value))) + value;
66 #elif defined(HOST_ARCH_IA32)
67 return static_cast<intptr_t>(
68 InterlockedAdd(reinterpret_cast<LONG*>(p),
69 static_cast<LONGLONG>(-value))) + value;
70 #else
71 #error Unsupported host architecture.
72 #endif
73 }
74
75
44 #if !defined(USING_SIMULATOR) 76 #if !defined(USING_SIMULATOR)
45 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr, 77 inline uword AtomicOperations::CompareAndSwapWord(uword* ptr,
46 uword old_value, 78 uword old_value,
47 uword new_value) { 79 uword new_value) {
48 #if defined(HOST_ARCH_X64) 80 #if defined(HOST_ARCH_X64)
49 return static_cast<uword>( 81 return static_cast<uword>(
50 InterlockedCompareExchange64(reinterpret_cast<LONGLONG*>(ptr), 82 InterlockedCompareExchange64(reinterpret_cast<LONGLONG*>(ptr),
51 static_cast<LONGLONG>(new_value), 83 static_cast<LONGLONG>(new_value),
52 static_cast<LONGLONG>(old_value))); 84 static_cast<LONGLONG>(old_value)));
53 #elif defined(HOST_ARCH_IA32) 85 #elif defined(HOST_ARCH_IA32)
(...skipping 15 matching lines...) Expand all
69 static_cast<LONG>(old_value))); 101 static_cast<LONG>(old_value)));
70 #else 102 #else
71 #error Unsupported host architecture. 103 #error Unsupported host architecture.
72 #endif 104 #endif
73 } 105 }
74 #endif // !defined(USING_SIMULATOR) 106 #endif // !defined(USING_SIMULATOR)
75 107
76 } // namespace dart 108 } // namespace dart
77 109
78 #endif // VM_ATOMIC_WIN_H_ 110 #endif // VM_ATOMIC_WIN_H_
OLDNEW
« no previous file with comments | « runtime/vm/atomic_test.cc ('k') | runtime/vm/pages.cc » ('j') | runtime/vm/pages.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698