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

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

Issue 2995803002: [vm] Implement more efficient CAS in simarm/simarm64 modes (Closed)
Patch Set: Correct comments Created 3 years, 4 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
« no previous file with comments | « no previous file | runtime/vm/atomic_android.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_H_ 5 #ifndef RUNTIME_VM_ATOMIC_H_
6 #define RUNTIME_VM_ATOMIC_H_ 6 #define RUNTIME_VM_ATOMIC_H_
7 7
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
11 #include "vm/simulator.h"
12 11
13 namespace dart { 12 namespace dart {
14 13
15 class AtomicOperations : public AllStatic { 14 class AtomicOperations : public AllStatic {
16 public: 15 public:
17 // Atomically fetch the value at p and increment the value at p. 16 // Atomically fetch the value at p and increment the value at p.
18 // Returns the original value at p. 17 // Returns the original value at p.
19 //
20 // NOTE: Not to be used for any atomic operations involving memory locations
21 // that are accessed by generated code.
22 static uintptr_t FetchAndIncrement(uintptr_t* p); 18 static uintptr_t FetchAndIncrement(uintptr_t* p);
23 static intptr_t FetchAndIncrement(intptr_t* p); 19 static intptr_t FetchAndIncrement(intptr_t* p);
24 20
25 // Atomically increment the value at p by 'value'. 21 // Atomically increment the value at p by 'value'.
26 //
27 // NOTE: Not to be used for any atomic operations involving memory locations
28 // that are accessed by generated code.
29 static void IncrementBy(intptr_t* p, intptr_t value); 22 static void IncrementBy(intptr_t* p, intptr_t value);
30 static void IncrementInt64By(int64_t* p, int64_t value); 23 static void IncrementInt64By(int64_t* p, int64_t value);
31 24
32 // Atomically fetch the value at p and decrement the value at p. 25 // Atomically fetch the value at p and decrement the value at p.
33 // Returns the original value at p. 26 // Returns the original value at p.
34 //
35 // NOTE: Not to be used for any atomic operations involving memory locations
36 // that are accessed by generated code.
37 static uintptr_t FetchAndDecrement(uintptr_t* p); 27 static uintptr_t FetchAndDecrement(uintptr_t* p);
38 static intptr_t FetchAndDecrement(intptr_t* p); 28 static intptr_t FetchAndDecrement(intptr_t* p);
39 29
40 // Atomically decrement the value at p by 'value'. 30 // Atomically decrement the value at p by 'value'.
41 //
42 // NOTE: Not to be used for any atomic operations involving memory locations
43 // that are accessed by generated code.
44 static void DecrementBy(intptr_t* p, intptr_t value); 31 static void DecrementBy(intptr_t* p, intptr_t value);
45 32
46 // Atomically compare *ptr to old_value, and if equal, store new_value. 33 // Atomically compare *ptr to old_value, and if equal, store new_value.
47 // Returns the original value at ptr. 34 // Returns the original value at ptr.
48 //
49 // NOTE: OK to use with memory locations that are accessed by generated code
50 static uword CompareAndSwapWord(uword* ptr, uword old_value, uword new_value); 35 static uword CompareAndSwapWord(uword* ptr, uword old_value, uword new_value);
51 static uint32_t CompareAndSwapUint32(uint32_t* ptr, 36 static uint32_t CompareAndSwapUint32(uint32_t* ptr,
52 uint32_t old_value, 37 uint32_t old_value,
53 uint32_t new_value); 38 uint32_t new_value);
54 39
55 // Performs a load of a word from 'ptr', but without any guarantees about 40 // Performs a load of a word from 'ptr', but without any guarantees about
56 // memory order (i.e., no load barriers/fences). 41 // memory order (i.e., no load barriers/fences).
57 template <typename T> 42 template <typename T>
58 static T LoadRelaxed(T* ptr) { 43 static T LoadRelaxed(T* ptr) {
59 return *static_cast<volatile T*>(ptr); 44 return *static_cast<volatile T*>(ptr);
60 } 45 }
61 }; 46 };
62 47
63 } // namespace dart 48 } // namespace dart
64 49
65 #if defined(USING_SIMULATOR) && !defined(TARGET_ARCH_DBC)
66 #define USING_SIMULATOR_ATOMICS
67 #endif
68
69 #if defined(USING_SIMULATOR_ATOMICS)
70 // We need to use the simulator to ensure that atomic operations are observed
71 // both in C++ and in generated code if the simulator is active.
72 #include "vm/atomic_simulator.h"
73 #endif
74
75 #if defined(HOST_OS_ANDROID) 50 #if defined(HOST_OS_ANDROID)
76 #include "vm/atomic_android.h" 51 #include "vm/atomic_android.h"
77 #elif defined(HOST_OS_FUCHSIA) 52 #elif defined(HOST_OS_FUCHSIA)
78 #include "vm/atomic_fuchsia.h" 53 #include "vm/atomic_fuchsia.h"
79 #elif defined(HOST_OS_LINUX) 54 #elif defined(HOST_OS_LINUX)
80 #include "vm/atomic_linux.h" 55 #include "vm/atomic_linux.h"
81 #elif defined(HOST_OS_MACOS) 56 #elif defined(HOST_OS_MACOS)
82 #include "vm/atomic_macos.h" 57 #include "vm/atomic_macos.h"
83 #elif defined(HOST_OS_WINDOWS) 58 #elif defined(HOST_OS_WINDOWS)
84 #include "vm/atomic_win.h" 59 #include "vm/atomic_win.h"
85 #else 60 #else
86 #error Unknown target os. 61 #error Unknown target os.
87 #endif 62 #endif
88 63
89 #endif // RUNTIME_VM_ATOMIC_H_ 64 #endif // RUNTIME_VM_ATOMIC_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/atomic_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698