7 #ifndef ZPP_INCLUDE_ZPP_SEM_HPP
8 #define ZPP_INCLUDE_ZPP_SEM_HPP
12 #include <zephyr/kernel.h>
13 #include <zephyr/sys/__assert.h>
23 template<
typename T_Sem>
40 std::numeric_limits<counter_type>::max();
54 [[nodiscard]]
bool take() noexcept
84 template<
class T_Rep,
class T_Period>
87 timeout_duration) noexcept
206 k_sem_init(&m_sem, initial_count, count_limit);
275 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
284 template<
class T_Sem>
286 : m_sem_ptr(s.native_handle())
288 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
302 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
314 template<
class T_Sem>
317 m_sem_ptr = s.native_handle();
318 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
329 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
341 __ASSERT_NO_MSG(m_sem_ptr !=
nullptr);
Counting semaphore base class.
void operator+=(int n) noexcept
Give the semaphore n times.
auto native_handle() const noexcept -> native_const_pointer
get the native zephyr sem handle.
void give() noexcept
Give the semaphore.
native_type * native_pointer
sem_base & operator=(sem_base &&)=delete
void operator-=(int n) noexcept
Take the semaphore n times, waiting forever.
sem_base(sem_base &&)=delete
void reset() noexcept
Reset the semaphore counter to zero.
void operator--(int) noexcept
Take the semaphore waiting forever.
void operator++(int) noexcept
Give the semaphore.
auto native_handle() noexcept -> native_pointer
get the native zephyr sem handle.
sem_base & operator=(const sem_base &)=delete
sem_base(const sem_base &)=delete
bool try_take_for(const std::chrono::duration< T_Rep, T_Period > &timeout_duration) noexcept
Try to take the semaphore waiting a certain timeout.
constexpr static counter_type max_count
Maximum value of the counter.
uint32_t counter_type
Type used as counter.
constexpr sem_base() noexcept
Default constructor, only allowed derived objects.
bool take() noexcept
Take the semaphore waiting forever.
bool try_take() noexcept
Try to take the semaphore without waiting.
native_type const * native_const_pointer
counter_type count() noexcept
Get current semaphore count.
A counting semaphore class borrowing the native sem.
constexpr sem_ref & operator=(native_pointer s) noexcept
Assign a sem using a native k_sem*.
constexpr sem_ref(T_Sem &s) noexcept
Construct a sem using a native k_sem*.
constexpr sem_ref(native_pointer s) noexcept
Construct a sem using a native k_sem*.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr sem handle.
constexpr sem_ref & operator=(T_Sem &s) noexcept
Assign a sem using another sem object.
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr sem handle.
A counting semaphore class.
sem & operator=(sem &&)=delete
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
sem() noexcept
Default onstructor.
sem(counter_type initial_count, counter_type count_limit) noexcept
Constructor initializing initial count and count limit.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
sem(counter_type initial_count) noexcept
Constructor initializing initial count.
sem & operator=(const sem &)=delete
void yield() noexcept
Yield the current thread.
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick