zpp
Zephyr C++20 Framework
zpp::sem_ref Class Reference

A counting semaphore class borrowing the native sem. More...

#include <sem.hpp>

Inheritance diagram for zpp::sem_ref:
[legend]
Collaboration diagram for zpp::sem_ref:
[legend]

Public Member Functions

constexpr sem_ref (native_pointer s) noexcept
 Construct a sem using a native k_sem*. More...
 
template<class T_Sem >
constexpr sem_ref (T_Sem &s) noexcept
 Construct a sem using a native k_sem*. More...
 
constexpr sem_refoperator= (native_pointer s) noexcept
 Assign a sem using a native k_sem*. More...
 
template<class T_Sem >
constexpr sem_refoperator= (T_Sem &s) noexcept
 Assign a sem using another sem object. More...
 
constexpr auto native_handle () noexcept -> native_pointer
 get the native zephyr sem handle. More...
 
constexpr auto native_handle () const noexcept -> native_const_pointer
 get the native zephyr sem handle. More...
 
 sem_ref ()=delete
 
- Public Member Functions inherited from zpp::sem_base< sem_ref >
 sem_base (const sem_base &)=delete
 
 sem_base (sem_base &&)=delete
 
bool take () noexcept
 Take the semaphore waiting forever. More...
 
bool try_take () noexcept
 Try to take the semaphore without waiting. More...
 
bool try_take_for (const std::chrono::duration< T_Rep, T_Period > &timeout_duration) noexcept
 Try to take the semaphore waiting a certain timeout. More...
 
void give () noexcept
 Give the semaphore. More...
 
void reset () noexcept
 Reset the semaphore counter to zero. More...
 
counter_type count () noexcept
 Get current semaphore count. More...
 
void operator++ (int) noexcept
 Give the semaphore. More...
 
void operator-- (int) noexcept
 Take the semaphore waiting forever. More...
 
void operator+= (int n) noexcept
 Give the semaphore n times. More...
 
void operator-= (int n) noexcept
 Take the semaphore n times, waiting forever. More...
 
auto native_handle () noexcept -> native_pointer
 get the native zephyr sem handle. More...
 
auto native_handle () const noexcept -> native_const_pointer
 get the native zephyr sem handle. More...
 
sem_baseoperator= (const sem_base &)=delete
 
sem_baseoperator= (sem_base &&)=delete
 

Additional Inherited Members

- Public Types inherited from zpp::sem_base< sem_ref >
using native_type = struct k_sem
 
using native_pointer = native_type *
 
using native_const_pointer = native_type const *
 
using counter_type = uint32_t
 Type used as counter. More...
 
- Static Public Attributes inherited from zpp::sem_base< sem_ref >
constexpr static counter_type max_count
 Maximum value of the counter. More...
 
- Protected Member Functions inherited from zpp::sem_base< sem_ref >
constexpr sem_base () noexcept
 Default constructor, only allowed derived objects. More...
 

Detailed Description

A counting semaphore class borrowing the native sem.

Definition at line 264 of file sem.hpp.

Constructor & Destructor Documentation

◆ sem_ref() [1/3]

constexpr zpp::sem_ref::sem_ref ( native_pointer  s)
inlineexplicitconstexprnoexcept

Construct a sem using a native k_sem*.

Parameters
sThe k_sem to use. s must already be initialized and will not be freed.

Definition at line 272 of file sem.hpp.

273  : m_sem_ptr(s)
274  {
275  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
276  }

◆ sem_ref() [2/3]

template<class T_Sem >
constexpr zpp::sem_ref::sem_ref ( T_Sem &  s)
inlineexplicitconstexprnoexcept

Construct a sem using a native k_sem*.

Parameters
sThe k_sem to use. s must already be initialized and will not be freed.

Definition at line 285 of file sem.hpp.

286  : m_sem_ptr(s.native_handle())
287  {
288  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
289  }

◆ sem_ref() [3/3]

zpp::sem_ref::sem_ref ( )
delete

Member Function Documentation

◆ native_handle() [1/2]

constexpr auto zpp::sem_ref::native_handle ( ) const -> native_const_pointer
inlineconstexprnoexcept

get the native zephyr sem handle.

Returns
A pointer to the zephyr k_sem.

Definition at line 339 of file sem.hpp.

340  {
341  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
342 
343  return m_sem_ptr;
344  }

◆ native_handle() [2/2]

constexpr auto zpp::sem_ref::native_handle ( ) -> native_pointer
inlineconstexprnoexcept

get the native zephyr sem handle.

Returns
A pointer to the zephyr k_sem.

Definition at line 327 of file sem.hpp.

328  {
329  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
330 
331  return m_sem_ptr;
332  }

◆ operator=() [1/2]

constexpr sem_ref& zpp::sem_ref::operator= ( native_pointer  s)
inlineconstexprnoexcept

Assign a sem using a native k_sem*.

Parameters
sThe k_sem to use. s must already be initialized and will not be freed.
Returns
reference to this object

Definition at line 299 of file sem.hpp.

300  {
301  m_sem_ptr = s;
302  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
303  return *this;
304  }

◆ operator=() [2/2]

template<class T_Sem >
constexpr sem_ref& zpp::sem_ref::operator= ( T_Sem &  s)
inlineconstexprnoexcept

Assign a sem using another sem object.

Parameters
sThe sem to use. s must already be initialized and will not be freed.
Returns
reference to this object

Definition at line 315 of file sem.hpp.

316  {
317  m_sem_ptr = s.native_handle();
318  __ASSERT_NO_MSG(m_sem_ptr != nullptr);
319  return *this;
320  }

The documentation for this class was generated from the following file: