#pragma once #include #include BEGIN_CS_NAMESPACE template struct AtomicPosition { using type = T; std::atomic value {}; AtomicPosition(T t) : value {t} {} AtomicPosition(const AtomicPosition &o) : AtomicPosition {o.get()} {} AtomicPosition(AtomicPosition &&o) : AtomicPosition {o.get()} {} AtomicPosition &operator=(const AtomicPosition &o) { this->set(o.get()); return *this; } AtomicPosition &operator=(AtomicPosition &&o) { this->set(o.get()); return *this; } constexpr static std::memory_order mo_rlx = std::memory_order_relaxed; void add(type other) { value.fetch_add(other, mo_rlx); } type get() const { return value.load(mo_rlx); } void set(type other) { value.store(other, mo_rlx); } type xchg(type other) { return value.exchange(other, mo_rlx); } void add_isr(type other) { add(other); } }; END_CS_NAMESPACE