zpp
Zephyr C++20 Framework
zpp::futex_base< T_Futex > Class Template Reference

A CRTP futex base class. More...

#include <futex.hpp>

Public Types

using native_type = struct k_futex
 
using native_pointer = native_type *
 
using native_const_pointer = native_type const *
 

Public Member Functions

bool wait (int expected) noexcept
 Wait for the futex. More...
 
bool try_wait (int expected) noexcept
 Try wait for the futex. More...
 
template<class T_Rep , class T_Period >
bool try_wait_for (int expected, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
 Wait for the futex. More...
 
void wake_one () noexcept
 Wakeup one waiting thread. More...
 
void wake_all () noexcept
 Wakeup all waiting threads. More...
 
auto native_handle () noexcept -> native_pointer
 get the native zephyr futex handle. More...
 
auto native_handle () const noexcept -> native_const_pointer
 get the native zephyr futex handle. More...
 
 futex_base (const futex_base &)=delete
 
 futex_base (futex_base &&)=delete
 
futex_baseoperator= (const futex_base &)=delete
 
futex_baseoperator= (futex_base &&)=delete
 

Protected Member Functions

constexpr futex_base () noexcept
 Default constructor. More...
 

Detailed Description

template<typename T_Futex>
class zpp::futex_base< T_Futex >

A CRTP futex base class.

Definition at line 23 of file futex.hpp.

Member Typedef Documentation

◆ native_const_pointer

template<typename T_Futex >
using zpp::futex_base< T_Futex >::native_const_pointer = native_type const *

Definition at line 28 of file futex.hpp.

◆ native_pointer

template<typename T_Futex >
using zpp::futex_base< T_Futex >::native_pointer = native_type *

Definition at line 27 of file futex.hpp.

◆ native_type

template<typename T_Futex >
using zpp::futex_base< T_Futex >::native_type = struct k_futex

Definition at line 26 of file futex.hpp.

Constructor & Destructor Documentation

◆ futex_base() [1/3]

template<typename T_Futex >
constexpr zpp::futex_base< T_Futex >::futex_base ( )
inlineconstexprprotectednoexcept

Default constructor.

Definition at line 33 of file futex.hpp.

34  {
35  }

◆ futex_base() [2/3]

template<typename T_Futex >
zpp::futex_base< T_Futex >::futex_base ( const futex_base< T_Futex > &  )
delete

◆ futex_base() [3/3]

template<typename T_Futex >
zpp::futex_base< T_Futex >::futex_base ( futex_base< T_Futex > &&  )
delete

Member Function Documentation

◆ native_handle() [1/2]

template<typename T_Futex >
auto zpp::futex_base< T_Futex >::native_handle ( ) const -> native_const_pointer
inlinenoexcept

get the native zephyr futex handle.

Returns
A pointer to the zephyr k_futex.

Definition at line 123 of file futex.hpp.

124  {
125  return static_cast<const T_Futex*>(this)->native_handle();
126  }
auto native_handle() noexcept -> native_pointer
get the native zephyr futex handle.
Definition: futex.hpp:113

References zpp::futex_base< T_Futex >::native_handle().

◆ native_handle() [2/2]

template<typename T_Futex >
auto zpp::futex_base< T_Futex >::native_handle ( ) -> native_pointer
inlinenoexcept

get the native zephyr futex handle.

Returns
A pointer to the zephyr k_futex.

Definition at line 113 of file futex.hpp.

114  {
115  return static_cast<T_Futex*>(this)->native_handle();
116  }

Referenced by zpp::futex_base< T_Futex >::native_handle(), zpp::futex_base< T_Futex >::try_wait(), zpp::futex_base< T_Futex >::try_wait_for(), zpp::futex_base< T_Futex >::wait(), zpp::futex_base< T_Futex >::wake_all(), and zpp::futex_base< T_Futex >::wake_one().

◆ operator=() [1/2]

template<typename T_Futex >
futex_base& zpp::futex_base< T_Futex >::operator= ( const futex_base< T_Futex > &  )
delete

◆ operator=() [2/2]

template<typename T_Futex >
futex_base& zpp::futex_base< T_Futex >::operator= ( futex_base< T_Futex > &&  )
delete

◆ try_wait()

template<typename T_Futex >
bool zpp::futex_base< T_Futex >::try_wait ( int  expected)
inlinenoexcept

Try wait for the futex.

Parameters
expectedthe expected value
Returns
true if successfull

Definition at line 61 of file futex.hpp.

62  {
63  if (futex_wait(native_handle(), expected, K_NO_WAIT) == 0) {
64  return true;
65  } else {
66  return false;
67  }
68  }

References zpp::futex_base< T_Futex >::native_handle().

◆ try_wait_for()

template<typename T_Futex >
template<class T_Rep , class T_Period >
bool zpp::futex_base< T_Futex >::try_wait_for ( int  expected,
const std::chrono::duration< T_Rep, T_Period > &  timeout 
)
inlinenoexcept

Wait for the futex.

Parameters
expectedthe expected value
timeoutthe timeout before returning
Returns
true if successfull

Definition at line 80 of file futex.hpp.

81  {
82  using namespace std::chrono;
83 
84  if (futex_wait(native_handle(), expected, to_timeout(timeout)) == 0)
85  {
86  return true;
87  } else {
88  return false;
89  }
90  }
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick
Definition: clock.hpp:88

References zpp::futex_base< T_Futex >::native_handle(), and zpp::to_timeout().

◆ wait()

template<typename T_Futex >
bool zpp::futex_base< T_Futex >::wait ( int  expected)
inlinenoexcept

Wait for the futex.

Parameters
expectedthe expected value
Returns
true if successfull

Definition at line 45 of file futex.hpp.

46  {
47  if (futex_wait(native_handle(), expected, K_FOREVER) == 0) {
48  return true;
49  } else {
50  return false;
51  }
52  }

References zpp::futex_base< T_Futex >::native_handle().

◆ wake_all()

template<typename T_Futex >
void zpp::futex_base< T_Futex >::wake_all ( )
inlinenoexcept

Wakeup all waiting threads.

Definition at line 103 of file futex.hpp.

104  {
105  futex_wake(native_handle(), true);
106  }

References zpp::futex_base< T_Futex >::native_handle().

◆ wake_one()

template<typename T_Futex >
void zpp::futex_base< T_Futex >::wake_one ( )
inlinenoexcept

Wakeup one waiting thread.

Definition at line 95 of file futex.hpp.

96  {
97  futex_wake(native_handle(), false);
98  }

References zpp::futex_base< T_Futex >::native_handle().


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