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

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

Issue 2408233004: [heap] Old-to-new pointer updates need atomic accessors. (Closed)
Patch Set: 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') | src/heap/mark-compact.cc » ('J')
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..f046ab9164e622d92b1642f53831a01d718d4ec7 100644
--- a/src/base/atomic-utils.h
+++ b/src/base/atomic-utils.h
@@ -51,6 +51,49 @@ class AtomicNumber {
base::AtomicWord value_;
};
+// This type uses no barrier accessors to change atomic value. Be careful with
+// data races.
+template <typename T>
+class NonAtomicValue {
Michael Lippautz 2016/10/12 08:04:15 You sure about this name? I'd rather call it NoBa
ulan 2016/10/12 08:32:39 +1 to NoBarrierAtomicValue
Hannes Payer (out of office) 2016/10/12 11:27:45 Changed the name. Note that the no barrier accesso
+ public:
+ NonAtomicValue() : value_(0) {}
+
+ explicit NonAtomicValue(T initial)
+ : value_(cast_helper<T>::to_storage_type(initial)) {}
+
+ 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') | src/heap/mark-compact.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698