#ifndef SCANN_UTILS_ATOMIC_H_
#define SCANN_UTILS_ATOMIC_H_
#include <atomic>
namespace research_scann {
template <typename T>
class RelaxedAtomic {
public:
RelaxedAtomic() = default;
explicit RelaxedAtomic(T value) : value_(value) {}
RelaxedAtomic(const RelaxedAtomic& other)
: value_(other.value_.load(std::memory_order_relaxed)) {}
RelaxedAtomic& operator=(const RelaxedAtomic& other) {
value_.store(other.value_.load(std::memory_order_relaxed),
std::memory_order_relaxed);
return *this;
}
RelaxedAtomic(RelaxedAtomic&& other) noexcept
: value_(other.value_.load(std::memory_order_relaxed)) {}
RelaxedAtomic& operator=(RelaxedAtomic&& other) noexcept {
value_.store(other.value_.load(std::memory_order_relaxed),
std::memory_order_relaxed);
return *this;
}
explicit operator T() const { return value_.load(std::memory_order_relaxed); }
T load() const { return value_.load(std::memory_order_relaxed); }
void store(T value) { value_.store(value, std::memory_order_relaxed); }
private:
std::atomic<T> value_;
};
}
#endif