Add subtract to atomics.
BUG=skia: Review URL: https://codereview.chromium.org/1348113004
This commit is contained in:
parent
42bd6bfd0d
commit
3667d5bf3f
@ -29,6 +29,9 @@ void sk_atomic_store(T*, T, sk_memory_order = sk_memory_order_seq_cst);
|
||||
template <typename T>
|
||||
T sk_atomic_fetch_add(T*, T, sk_memory_order = sk_memory_order_seq_cst);
|
||||
|
||||
template <typename T>
|
||||
T sk_atomic_fetch_sub(T*, T, sk_memory_order = sk_memory_order_seq_cst);
|
||||
|
||||
template <typename T>
|
||||
bool sk_atomic_compare_exchange(T*, T* expected, T desired,
|
||||
sk_memory_order success = sk_memory_order_seq_cst,
|
||||
@ -58,6 +61,10 @@ public:
|
||||
return sk_atomic_fetch_add(&fVal, val, mo);
|
||||
}
|
||||
|
||||
T fetch_sub(const T& val, sk_memory_order mo = sk_memory_order_seq_cst) {
|
||||
return sk_atomic_fetch_sub(&fVal, val, mo);
|
||||
}
|
||||
|
||||
bool compare_exchange(T* expected, const T& desired,
|
||||
sk_memory_order success = sk_memory_order_seq_cst,
|
||||
sk_memory_order failure = sk_memory_order_seq_cst) {
|
||||
|
@ -31,6 +31,12 @@ T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
|
||||
return __atomic_fetch_add(ptr, val, mo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T sk_atomic_fetch_sub(T* ptr, T val, sk_memory_order mo) {
|
||||
// All values of mo are valid.
|
||||
return __atomic_fetch_sub(ptr, val, mo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
|
||||
sk_memory_order success,
|
||||
|
@ -38,6 +38,13 @@ T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
|
||||
return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T sk_atomic_fetch_sub(T* ptr, T val, sk_memory_order mo) {
|
||||
// All values of mo are valid.
|
||||
std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
|
||||
return std::atomic_fetch_sub_explicit(ap, val, (std::memory_order)mo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
|
||||
sk_memory_order success,
|
||||
|
@ -45,6 +45,11 @@ T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order) {
|
||||
return __sync_fetch_and_add(ptr, val);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T sk_atomic_fetch_sub(T* ptr, T val, sk_memory_order) {
|
||||
return __sync_fetch_and_sub(ptr, val);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, sk_memory_order, sk_memory_order) {
|
||||
T prev = __sync_val_compare_and_swap(ptr, *expected, desired);
|
||||
|
Loading…
Reference in New Issue
Block a user