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

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

Issue 2353553003: [heap] Make slot set state and operations atomic. (Closed)
Patch Set: add check 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') | src/heap/slot-set.h » ('J')
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, int mask) {
ulan 2016/09/20 12:33:02 mask also should be T
Hannes Payer (out of office) 2016/09/20 13:51:29 Done.
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) { SetBits(1 << bit, 1 << bit); }
ulan 2016/09/20 12:33:02 How about static_cast<T>(1) << bit to avoid potent
Hannes Payer (out of office) 2016/09/20 13:51:29 Done.
86
87 V8_INLINE void ClearBit(int bit) { SetBits(0, 1 << bit); }
88
75 V8_INLINE void SetValue(T new_value) { 89 V8_INLINE void SetValue(T new_value) {
76 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value)); 90 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value));
77 } 91 }
78 92
79 private: 93 private:
80 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); 94 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord));
81 95
82 template <typename S> 96 template <typename S>
83 struct cast_helper { 97 struct cast_helper {
84 static base::AtomicWord to_storage_type(S value) { 98 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; 189 return static_cast<base::AtomicWord>(1) << element;
176 } 190 }
177 191
178 base::AtomicWord bits_; 192 base::AtomicWord bits_;
179 }; 193 };
180 194
181 } // namespace base 195 } // namespace base
182 } // namespace v8 196 } // namespace v8
183 197
184 #endif // #define V8_ATOMIC_UTILS_H_ 198 #endif // #define V8_ATOMIC_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/slot-set.h » ('j') | src/heap/slot-set.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698