Chromium Code Reviews| 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_H_ | 5 #ifndef VM_ATOMIC_H_ |
| 6 #define VM_ATOMIC_H_ | 6 #define 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" | 11 #include "vm/simulator.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 class AtomicOperations : public AllStatic { | 15 class AtomicOperations : public AllStatic { |
| 16 public: | 16 public: |
| 17 // Atomically fetch the value at p and increment the value at p. | 17 // Atomically fetch the value at p and increment the value at p. |
| 18 // Returns the original value at p. | 18 // Returns the original value at p. |
| 19 // | 19 // |
| 20 // NOTE: Not to be used for any atomic operations involving memory locations | 20 // NOTE: Not to be used for any atomic operations involving memory locations |
| 21 // that are accessed by generated code | 21 // that are accessed by generated code |
| 22 static uintptr_t FetchAndIncrement(uintptr_t* p); | 22 static uintptr_t FetchAndIncrement(uintptr_t* p); |
| 23 | 23 |
| 24 static intptr_t FetchAndAdd(intptr_t* p, intptr_t delta); | 24 static uintptr_t FetchAndDecrement(uintptr_t* p); |
|
Ivan Posva
2015/08/13 01:43:21
This also needs the comment from above. Especially
koda
2015/08/13 16:22:37
Done.
| |
| 25 | 25 |
| 26 static uword CompareAndSwapWord(uword* ptr, uword old_value, uword new_value); | 26 static uword CompareAndSwapWord(uword* ptr, uword old_value, uword new_value); |
|
Ivan Posva
2015/08/13 01:43:21
Please add a comment here as well plus the NOTE th
koda
2015/08/13 16:22:37
Done.
| |
| 27 | 27 |
| 28 // Performs a load of a word from 'ptr', but without any guarantees about | |
| 29 // memory order (i.e., no load barriers/fences). | |
| 28 static uword LoadRelaxed(uword* ptr) { | 30 static uword LoadRelaxed(uword* ptr) { |
| 29 uword result; | 31 return *static_cast<volatile uword*>(ptr); |
| 30 memcpy(&result, ptr, sizeof(result)); | |
| 31 return result; | |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 | 35 |
| 36 } // namespace dart | 36 } // namespace dart |
| 37 | 37 |
| 38 // We need to use the simulator to ensure that atomic operations are observed | 38 // We need to use the simulator to ensure that atomic operations are observed |
| 39 // both in C++ and in generated code if the simulator is active. | 39 // both in C++ and in generated code if the simulator is active. |
| 40 #include "vm/atomic_simulator.h" | 40 #include "vm/atomic_simulator.h" |
| 41 | 41 |
| 42 #if defined(TARGET_OS_ANDROID) | 42 #if defined(TARGET_OS_ANDROID) |
| 43 #include "vm/atomic_android.h" | 43 #include "vm/atomic_android.h" |
| 44 #elif defined(TARGET_OS_LINUX) | 44 #elif defined(TARGET_OS_LINUX) |
| 45 #include "vm/atomic_linux.h" | 45 #include "vm/atomic_linux.h" |
| 46 #elif defined(TARGET_OS_MACOS) | 46 #elif defined(TARGET_OS_MACOS) |
| 47 #include "vm/atomic_macos.h" | 47 #include "vm/atomic_macos.h" |
| 48 #elif defined(TARGET_OS_WINDOWS) | 48 #elif defined(TARGET_OS_WINDOWS) |
| 49 #include "vm/atomic_win.h" | 49 #include "vm/atomic_win.h" |
| 50 #else | 50 #else |
| 51 #error Unknown target os. | 51 #error Unknown target os. |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 #endif // VM_ATOMIC_H_ | 54 #endif // VM_ATOMIC_H_ |
| OLD | NEW |