7 #ifndef ZPP_INCLUDE_ZPP_ATOMIC_VAR_HPP
8 #define ZPP_INCLUDE_ZPP_ATOMIC_VAR_HPP
10 #include <zephyr/sys/atomic.h>
11 #include <zephyr/sys/__assert.h>
90 return atomic_cas(&m_var, old_val, new_val);
105 return atomic_add(&m_var, val);
120 return atomic_sub(&m_var, val);
135 return atomic_or(&m_var, val);
150 return atomic_xor(&m_var, val);
165 return atomic_and(&m_var, val);
180 return atomic_nand(&m_var, val);
193 return atomic_inc(&m_var);
206 return atomic_dec(&m_var);
217 return atomic_get(&m_var);
229 return atomic_set(&m_var, val);
239 return atomic_clear(&m_var);
249 [[nodiscard]]
bool load(
size_t bit)
const noexcept
251 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
252 return atomic_test_bit(&m_var, bit);
261 void store(
size_t bit,
bool val) noexcept
263 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
264 atomic_set_bit_to(&m_var, bit, val);
272 void set(
size_t bit) noexcept
274 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
275 atomic_set_bit(&m_var, bit);
285 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
286 atomic_clear_bit(&m_var, bit);
298 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
299 return atomic_test_and_clear_bit(&m_var, bit);
311 __ASSERT_NO_MSG(bit < (
sizeof(
value_type) * 8));
312 return atomic_test_and_set_bit(&m_var, bit);
class wrapping an atomic_var_t
value_type operator&=(value_type val) noexcept
Perform atomic bitwise AND.
void clear(size_t bit) noexcept
atomically set a bit to false/0
void set(size_t bit) noexcept
atomically set a bit to true/1
value_type fetch_and(value_type val) noexcept
Atomic bitwise AND.
void store(size_t bit, bool val) noexcept
atomically set a bit a value
value_type store(value_type val) noexcept
Atomically replace current value of the atomic variable.
value_type fetch_inc() noexcept
Atomic increment.
value_type operator++(int) noexcept
Perform atomic post-increment.
value_type fetch_xor(value_type val) noexcept
Atomic bitwise XOR.
value_type operator--() noexcept
Perform atomic pre-decrement.
bool fetch_and_clear(size_t bit) noexcept
atomically clear a bit while returning the previous value.
value_type fetch_dec() noexcept
Atomic decrement.
value_type fetch_or(value_type val) noexcept
Atomic bitwise OR.
atomic_val_t value_type
the type used to store the value
value_type operator-=(value_type val) noexcept
Perform atomic substraction.
bool load(size_t bit) const noexcept
atomically get a bit from the bitset
atomic_var(const atomic_var &rhs) noexcept
copy constructor
value_type fetch_nand(value_type val) noexcept
Atomic bitwise NAND.
bool cas(value_type old_val, value_type new_val) noexcept
Atomic compare-and-set.
value_type fetch_add(value_type val) noexcept
Atomic addition.
constexpr size_t bit_count() const noexcept
the size in bits of value_type
constexpr atomic_var() noexcept=default
default constructor that sets the value to 0
value_type operator++() noexcept
Perform atomic pre-increment.
value_type operator|=(value_type val) noexcept
Perform atomic bitwise OR.
value_type fetch_sub(value_type val) noexcept
Atomic substraction.
value_type operator--(int) noexcept
Perform atomic post-decrement.
value_type operator=(value_type val) noexcept
Atomically replace current value of the atomic variable.
value_type operator+=(value_type val) noexcept
Perform atomic addition.
value_type clear() noexcept
Atomically clear the atomic variable.
value_type load() const noexcept
Atomically loads and returns the current value of the atomic variable.
bool fetch_and_set(size_t bit) noexcept
atomically set a bit while returning the previous value.
atomic_var & operator=(const atomic_var &rhs) noexcept
copy operator
value_type operator^=(value_type val) noexcept
Perform atomic bitwise XOR.