diff options
Diffstat (limited to 'src/include/atomic_support.h')
-rw-r--r-- | src/include/atomic_support.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/include/atomic_support.h b/src/include/atomic_support.h index 96dbd2c..c9f8a5a 100644 --- a/src/include/atomic_support.h +++ b/src/include/atomic_support.h @@ -151,7 +151,7 @@ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a, template <class _ValueType> inline _LIBCPP_INLINE_VISIBILITY _ValueType __libcpp_atomic_exchange(_ValueType* __target, - _ValueType __value, int __order = _AO_Seq) + _ValueType __value, int = _AO_Seq) { _ValueType old = *__target; *__target = __value; @@ -178,4 +178,34 @@ bool __libcpp_atomic_compare_exchange(_ValueType* __val, _LIBCPP_END_NAMESPACE_STD +namespace { + +template <class IntType> +class AtomicInt { +public: + using MemoryOrder = std::__libcpp_atomic_order; + + explicit AtomicInt(IntType *b) : b(b) {} + AtomicInt(AtomicInt const&) = delete; + AtomicInt& operator=(AtomicInt const&) = delete; + + IntType load(MemoryOrder ord) { + return std::__libcpp_atomic_load(b, ord); + } + void store(IntType val, MemoryOrder ord) { + std::__libcpp_atomic_store(b, val, ord); + } + IntType exchange(IntType new_val, MemoryOrder ord) { + return std::__libcpp_atomic_exchange(b, new_val, ord); + } + bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) { + return std::__libcpp_atomic_compare_exchange(b, expected, desired, ord_success, ord_failure); + } + +private: + IntType *b; +}; + +} // end namespace + #endif // ATOMIC_SUPPORT_H |