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

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

Issue 2215693002: [base] Add Decrement and assignment operators to AtomicNumber (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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 | test/unittests/base/atomic-utils-unittest.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 6731a810f18c06f7929c21e2ec9c7f5466bccbe0..e19385dcb15742909517cb208f048d10dfee9ea7 100644
--- a/src/base/atomic-utils.h
+++ b/src/base/atomic-utils.h
@@ -19,12 +19,18 @@ class AtomicNumber {
AtomicNumber() : value_(0) {}
explicit AtomicNumber(T initial) : value_(initial) {}
- // Returns the newly set value.
+ // Returns the value after incrementing.
V8_INLINE T Increment(T increment) {
return static_cast<T>(base::Barrier_AtomicIncrement(
&value_, static_cast<base::AtomicWord>(increment)));
}
+ // Returns the value after decrementing.
+ V8_INLINE T Decrement(T decrement) {
+ return static_cast<T>(base::Barrier_AtomicIncrement(
+ &value_, -static_cast<base::AtomicWord>(decrement)));
+ }
+
V8_INLINE T Value() { return static_cast<T>(base::Acquire_Load(&value_)); }
V8_INLINE void SetValue(T new_value) {
@@ -36,6 +42,9 @@ class AtomicNumber {
return value;
}
+ V8_INLINE T operator+=(T value) { return Increment(value); }
+ V8_INLINE T operator-=(T value) { return Decrement(value); }
+
private:
STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord));
« no previous file with comments | « no previous file | test/unittests/base/atomic-utils-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698