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

Side by Side Diff: src/base/atomic-utils.h

Issue 2353553003: [heap] Make slot set state and operations atomic. (Closed)
Patch Set: comments Created 4 years, 3 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 | src/heap/slot-set.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ATOMIC_UTILS_H_ 5 #ifndef V8_ATOMIC_UTILS_H_
6 #define V8_ATOMIC_UTILS_H_ 6 #define V8_ATOMIC_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 9
10 #include "src/base/atomicops.h" 10 #include "src/base/atomicops.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_)); 65 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_));
66 } 66 }
67 67
68 V8_INLINE bool TrySetValue(T old_value, T new_value) { 68 V8_INLINE bool TrySetValue(T old_value, T new_value) {
69 return base::Release_CompareAndSwap( 69 return base::Release_CompareAndSwap(
70 &value_, cast_helper<T>::to_storage_type(old_value), 70 &value_, cast_helper<T>::to_storage_type(old_value),
71 cast_helper<T>::to_storage_type(new_value)) == 71 cast_helper<T>::to_storage_type(new_value)) ==
72 cast_helper<T>::to_storage_type(old_value); 72 cast_helper<T>::to_storage_type(old_value);
73 } 73 }
74 74
75 V8_INLINE void SetBits(T bits, T mask) {
76 DCHECK_EQ(bits & ~mask, 0);
77 T old_value;
78 T new_value;
79 do {
80 old_value = Value();
81 new_value = (old_value & ~mask) | bits;
82 } while (!TrySetValue(old_value, new_value));
83 }
84
85 V8_INLINE void SetBit(int bit) {
86 SetBits(static_cast<T>(1) << bit, static_cast<T>(1) << bit);
87 }
88
89 V8_INLINE void ClearBit(int bit) { SetBits(0, 1 << bit); }
90
75 V8_INLINE void SetValue(T new_value) { 91 V8_INLINE void SetValue(T new_value) {
76 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value)); 92 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value));
77 } 93 }
78 94
79 private: 95 private:
80 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); 96 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord));
81 97
82 template <typename S> 98 template <typename S>
83 struct cast_helper { 99 struct cast_helper {
84 static base::AtomicWord to_storage_type(S value) { 100 static base::AtomicWord to_storage_type(S value) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return static_cast<base::AtomicWord>(1) << element; 191 return static_cast<base::AtomicWord>(1) << element;
176 } 192 }
177 193
178 base::AtomicWord bits_; 194 base::AtomicWord bits_;
179 }; 195 };
180 196
181 } // namespace base 197 } // namespace base
182 } // namespace v8 198 } // namespace v8
183 199
184 #endif // #define V8_ATOMIC_UTILS_H_ 200 #endif // #define V8_ATOMIC_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/slot-set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698