OLD | NEW |
(Empty) | |
| 1 #ifndef SkAtomics_std_DEFINED |
| 2 #define SkAtomics_std_DEFINED |
| 3 |
| 4 // We try not to depend on the C++ standard library, |
| 5 // but these uses of <atomic> should all inline, so we don't feel to bad here. |
| 6 #include <atomic> |
| 7 |
| 8 template <typename T> |
| 9 T sk_atomic_load(const T* ptr, sk_memory_order mo) { |
| 10 const std::atomic<T>* ap = reinterpret_cast<const std::atomic<T>*>(ptr); |
| 11 return std::atomic_load_explicit(ap, (std::memory_order)mo); |
| 12 } |
| 13 |
| 14 template <typename T> |
| 15 void sk_atomic_store(T* ptr, T val, sk_memory_order mo) { |
| 16 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); |
| 17 return std::atomic_store_explicit(ap, val, (std::memory_order)mo); |
| 18 } |
| 19 |
| 20 template <typename T> |
| 21 T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) { |
| 22 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); |
| 23 return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo); |
| 24 } |
| 25 |
| 26 template <typename T> |
| 27 bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, |
| 28 sk_memory_order success, |
| 29 sk_memory_order failure) { |
| 30 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); |
| 31 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired, |
| 32 (std::memory_order)succe
ss, |
| 33 (std::memory_order)failu
re); |
| 34 } |
| 35 |
| 36 #endif//SkAtomics_std_DEFINED |
OLD | NEW |