You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mobileatomic.h 749B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <cstdint>
  3. #include <atomic>
  4. namespace util {
  5. template<typename T>
  6. struct MobileAtomic
  7. {
  8. std::atomic<T> atomic;
  9. MobileAtomic() : atomic(T()) {}
  10. explicit MobileAtomic ( T const& v ) : atomic ( v ) {}
  11. explicit MobileAtomic ( std::atomic<T> const& a ) : atomic ( a.load() ) {}
  12. inline T load(const std::memory_order& order = std::memory_order_seq_cst) {
  13. return atomic.load(order);
  14. }
  15. inline void store(const T& desired, const std::memory_order& order = std::memory_order_seq_cst) {
  16. atomic.store(desired, order);
  17. }
  18. MobileAtomic ( MobileAtomic const&other ) : atomic( other.atomic.load() ) {}
  19. MobileAtomic& operator=( MobileAtomic const &other )
  20. {
  21. atomic.store( other.atomic.load() );
  22. return *this;
  23. }
  24. };
  25. }