7 #ifndef ZPP_INCLUDE_ZPP_ATOMIC_BITSET_HPP
8 #define ZPP_INCLUDE_ZPP_ATOMIC_BITSET_HPP
10 #include <zephyr/sys/atomic.h>
11 #include <zephyr/sys/__assert.h>
22 template<
size_t T_BitsetSize>
50 [[nodiscard]]
bool load(
size_t bit)
const noexcept
52 __ASSERT_NO_MSG(bit < T_BitsetSize);
53 return atomic_test_bit(m_var, bit);
62 void store(
size_t bit,
bool val) noexcept
64 __ASSERT_NO_MSG(bit < T_BitsetSize);
65 atomic_set_bit_to(m_var, bit, val);
73 void set(
size_t bit) noexcept
75 __ASSERT_NO_MSG(bit < T_BitsetSize);
76 atomic_set_bit(m_var, bit);
86 __ASSERT_NO_MSG(bit < T_BitsetSize);
87 atomic_clear_bit(m_var, bit);
99 __ASSERT_NO_MSG(bit < T_BitsetSize);
100 return atomic_test_and_clear_bit(m_var, bit);
112 __ASSERT_NO_MSG(bit < T_BitsetSize);
113 return atomic_test_and_set_bit(m_var, bit);
116 ATOMIC_DEFINE(m_var, T_BitsetSize) {};
class wrapping an atomic_var_t array
constexpr atomic_bitset() noexcept=default
default constructor
void clear(size_t bit) noexcept
atomically set a bit to false/0
atomic_bitset & operator=(const atomic_bitset &)=delete
bool load(size_t bit) const noexcept
atomically get a bit from the bitset
bool fetch_and_set(size_t bit) noexcept
atomically set a bit while returning the previous value.
bool fetch_and_clear(size_t bit) noexcept
atomically clear a bit while returning the previous value.
atomic_bitset(const atomic_bitset &)=delete
atomic_bitset(atomic_bitset &&)=delete
constexpr size_t bit_count() const noexcept
return size of the bitset
void store(size_t bit, bool val) noexcept
atomically set a bit a value
void set(size_t bit) noexcept
atomically set a bit to true/1
atomic_bitset & operator=(atomic_bitset &&)=delete