summaryrefslogtreecommitdiff
path: root/runtime/atomic_integer.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/atomic_integer.h')
-rw-r--r--runtime/atomic_integer.h40
1 files changed, 22 insertions, 18 deletions
diff --git a/runtime/atomic_integer.h b/runtime/atomic_integer.h
index 117e837bdb..34924877d7 100644
--- a/runtime/atomic_integer.h
+++ b/runtime/atomic_integer.h
@@ -29,47 +29,51 @@ class AtomicInteger {
explicit AtomicInteger(int32_t value) : value_(value) { }
// Unsafe = operator for non atomic operations on the integer.
- AtomicInteger& operator = (int32_t new_value) {
- value_ = new_value;
+ void store(int32_t desired) {
+ value_ = desired;
+ }
+
+ AtomicInteger& operator=(int32_t desired) {
+ store(desired);
return *this;
}
- operator int32_t () const {
+ int32_t load() const {
return value_;
}
- int32_t get() const {
- return value_;
+ operator int32_t() const {
+ return load();
}
- int32_t operator += (const int32_t value) {
+ int32_t fetch_add(const int32_t value) {
return android_atomic_add(value, &value_);
}
- int32_t operator -= (const int32_t value) {
+ int32_t fetch_sub(const int32_t value) {
return android_atomic_add(-value, &value_);
}
- int32_t operator |= (const int32_t value) {
- return android_atomic_or(value, &value_);
+ int32_t operator++() {
+ return android_atomic_inc(&value_) + 1;
}
- int32_t operator &= (const int32_t value) {
- return android_atomic_and(-value, &value_);
+ int32_t operator++(int32_t) {
+ return android_atomic_inc(&value_);
}
- int32_t operator ++ () {
- return android_atomic_inc(&value_) + 1;
+ int32_t operator--() {
+ return android_atomic_dec(&value_) - 1;
}
- int32_t operator -- () {
- return android_atomic_dec(&value_) - 1;
+ int32_t operator--(int32_t) {
+ return android_atomic_dec(&value_);
}
- bool CompareAndSwap(int expected_value, int new_value) {
- bool success = android_atomic_cas(expected_value, new_value, &value_) == 0;
- return success;
+ bool compare_and_swap(int32_t expected_value, int32_t desired_value) {
+ return android_atomic_cas(expected_value, desired_value, &value_) == 0;
}
+
private:
volatile int32_t value_;
};