7 #ifndef ZPP_INCLUDE_ZPP_CONDITION_VARIABLE_HPP
8 #define ZPP_INCLUDE_ZPP_CONDITION_VARIABLE_HPP
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/__assert.h>
25 template<
typename T_ConditionVariable>
84 template<
class T_Mutex>
85 [[nodiscard]]
auto wait(T_Mutex& m) noexcept
89 auto h = m.native_handle();
112 template <
class T_Mutex,
class T_Rep,
class T_Period>
114 try_wait_for(T_Mutex& m,
const std::chrono::duration<T_Rep, T_Period>& timeout) noexcept
116 using namespace std::chrono;
120 auto h = m.native_handle();
144 template<
class T_Mutex,
class T_Predecate>
145 [[nodiscard]]
auto wait(T_Mutex& m, T_Predecate pred) noexcept
149 auto h = m.native_handle();
153 while (pred() ==
false) {
176 template <
class T_Mutex,
class T_Rep,
class T_Period,
class T_Predecate>
178 try_wait_for(T_Mutex& m,
const std::chrono::duration<T_Rep, T_Period>& timeout, T_Predecate pred) noexcept
180 using namespace std::chrono;
184 auto h = m.native_handle();
188 while(pred() ==
false) {
211 return static_cast<T_ConditionVariable*
>(
this)->
native_handle();
221 return static_cast<const T_ConditionVariable*
>(
this)->
native_handle();
241 k_condvar_init(&m_condvar);
292 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
303 template<
class T_ContitionVariable>
305 : m_condvar_ptr(cv.native_handle())
307 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
321 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
333 template<
class T_ContitionVariable>
337 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
348 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
350 return m_condvar_ptr;
360 __ASSERT_NO_MSG(m_condvar_ptr !=
nullptr);
362 return m_condvar_ptr;
A condition variable CRTP base class.
condition_variable_base & operator=(condition_variable_base &&)=delete
auto notify_one() noexcept
Notify one waiter.
auto native_handle() noexcept -> native_pointer
get the native zephyr k_condvar pointer.
constexpr condition_variable_base() noexcept=default
Protected default constructor so only derived classes can be created.
auto try_wait_for(T_Mutex &m, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
Try waiting with a timeout to see if the variable is signaled.
condition_variable_base(const condition_variable_base &)=delete
auto wait(T_Mutex &m) noexcept
wait for ever until the variable is signaled.
condition_variable_base & operator=(const condition_variable_base &)=delete
auto try_wait_for(T_Mutex &m, const std::chrono::duration< T_Rep, T_Period > &timeout, T_Predecate pred) noexcept
Try waiting with a timeout to see if the variable is signaled.
auto notify_all() noexcept
Notify all waiters.
auto wait(T_Mutex &m, T_Predecate pred) noexcept
wait for ever until the variable is signaled.
auto native_handle() const noexcept -> native_const_pointer
get the native zephyr k_condvar pointer.
struct k_condvar native_type
native_type const * native_const_pointer
condition_variable_base(condition_variable_base &&)=delete
native_type * native_pointer
A class using a reference to another native condition variable or zpp::condition_variable.
condition_variable_ref & operator=(const T_ContitionVariable &cv) noexcept
copy a condition variable using another condition variable
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr condition variable handle.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr condition variable handle.
constexpr condition_variable_ref(const T_ContitionVariable &cv) noexcept
Construct a condition variable using another condition variable.
condition_variable_ref & operator=(native_pointer cv) noexcept
copy a condition variable using another condition variable
constexpr condition_variable_ref(native_pointer cv) noexcept
Construct a condition variable using a native k_condvar*.
A condition variable class.
condition_variable(const condition_variable &)=delete
condition_variable & operator=(condition_variable &&)=delete
condition_variable() noexcept
Default constructor.
condition_variable(condition_variable &&)=delete
condition_variable & operator=(const condition_variable &)=delete
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr condition variable handle.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr condition variable handle.
void assign_value(const T_Ok &v) noexcept
void assign_error(const T_Error &e) noexcept
constexpr error_code to_error_code(int v) noexcept
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick
@ k_inval
Invalid argument.