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

A counting semaphore class. More...

#include <sem.hpp>

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

Public Member Functions

 sem (counter_type initial_count, counter_type count_limit) noexcept
 Constructor initializing initial count and count limit. More...
 
 sem (counter_type initial_count) noexcept
 Constructor initializing initial count. More...
 
 sem () noexcept
 Default onstructor. More...
 
constexpr auto native_handle () noexcept -> native_pointer
 get the native zephyr mutex handle. More...
 
constexpr auto native_handle () const noexcept -> native_const_pointer
 get the native zephyr mutex handle. More...
 
 sem (const sem &)=delete
 
 sem (sem &&)=delete
 
semoperator= (const sem &)=delete
 
semoperator= (sem &&)=delete
 
- Public Member Functions inherited from zpp::sem_base< sem >
 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 >
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 >
constexpr static counter_type max_count
 Maximum value of the counter. More...
 
- Protected Member Functions inherited from zpp::sem_base< sem >
constexpr sem_base () noexcept
 Default constructor, only allowed derived objects. More...
 

Detailed Description

A counting semaphore class.

Definition at line 196 of file sem.hpp.

Constructor & Destructor Documentation

◆ sem() [1/5]

zpp::sem::sem ( counter_type  initial_count,
counter_type  count_limit 
)
inlinenoexcept

Constructor initializing initial count and count limit.

Parameters
initial_countThe initial count value for the semaphore
count_limitThe maxium count the semaphore can have

Definition at line 204 of file sem.hpp.

205  {
206  k_sem_init(&m_sem, initial_count, count_limit);
207  }

◆ sem() [2/5]

zpp::sem::sem ( counter_type  initial_count)
inlineexplicitnoexcept

Constructor initializing initial count.

Contructor initializing initial count to initial_count and the maxium count limit to max_count.

Parameters
initial_countThe initial count value for the semaphore

Definition at line 217 of file sem.hpp.

218  : sem(initial_count, max_count)
219  {
220  }
constexpr static counter_type max_count
Maximum value of the counter.
Definition: sem.hpp:39
sem() noexcept
Default onstructor.
Definition: sem.hpp:228

◆ sem() [3/5]

zpp::sem::sem ( )
inlinenoexcept

Default onstructor.

Contructor initializing initial count to 0 and the maxium count limit to max_count.

Definition at line 228 of file sem.hpp.

229  : sem(0, max_count)
230  {
231  }

◆ sem() [4/5]

zpp::sem::sem ( const sem )
delete

◆ sem() [5/5]

zpp::sem::sem ( sem &&  )
delete

Member Function Documentation

◆ native_handle() [1/2]

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

get the native zephyr mutex handle.

Returns
A pointer to the zephyr k_mutex.

Definition at line 248 of file sem.hpp.

249  {
250  return &m_sem;
251  }

◆ native_handle() [2/2]

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

get the native zephyr mutex handle.

Returns
A pointer to the zephyr k_mutex.

Definition at line 238 of file sem.hpp.

239  {
240  return &m_sem;
241  }

◆ operator=() [1/2]

sem& zpp::sem::operator= ( const sem )
delete

◆ operator=() [2/2]

sem& zpp::sem::operator= ( sem &&  )
delete

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