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

Unified Diff: src/base/atomic-utils.h

Issue 2408233004: [heap] Old-to-new pointer updates need atomic accessors. (Closed)
Patch Set: inline check Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/heap/mark-compact.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/atomic-utils.h
diff --git a/src/base/atomic-utils.h b/src/base/atomic-utils.h
index 31db603bf94345bb84ce9ef7b135c513f8f9da3a..7931c7376ab4b5ba4bf27268bbeb124fec6acef8 100644
--- a/src/base/atomic-utils.h
+++ b/src/base/atomic-utils.h
@@ -51,6 +51,53 @@ class AtomicNumber {
base::AtomicWord value_;
};
+// This type uses no barrier accessors to change atomic word. Be careful with
+// data races.
+template <typename T>
+class NoBarrierAtomicValue {
+ public:
+ NoBarrierAtomicValue() : value_(0) {}
+
+ explicit NoBarrierAtomicValue(T initial)
+ : value_(cast_helper<T>::to_storage_type(initial)) {}
+
+ static NoBarrierAtomicValue* FromAddress(void* address) {
+ return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address);
+ }
+
+ V8_INLINE T Value() const {
+ return cast_helper<T>::to_return_type(base::NoBarrier_Load(&value_));
+ }
+
+ V8_INLINE void SetValue(T new_value) {
+ base::NoBarrier_Store(&value_, cast_helper<T>::to_storage_type(new_value));
+ }
+
+ private:
+ STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord));
+
+ template <typename S>
+ struct cast_helper {
+ static base::AtomicWord to_storage_type(S value) {
+ return static_cast<base::AtomicWord>(value);
+ }
+ static S to_return_type(base::AtomicWord value) {
+ return static_cast<S>(value);
+ }
+ };
+
+ template <typename S>
+ struct cast_helper<S*> {
+ static base::AtomicWord to_storage_type(S* value) {
+ return reinterpret_cast<base::AtomicWord>(value);
+ }
+ static S* to_return_type(base::AtomicWord value) {
+ return reinterpret_cast<S*>(value);
+ }
+ };
+
+ base::AtomicWord value_;
+};
// Flag using T atomically. Also accepts void* as T.
template <typename T>
« no previous file with comments | « no previous file | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698