7 #ifndef ZPP_INCLUDE_ZPP_MUTEX_HPP
8 #define ZPP_INCLUDE_ZPP_MUTEX_HPP
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/__assert.h>
23 template<
typename T_Mutex>
44 [[nodiscard]]
auto lock() noexcept
84 template<
class T_Rep,
class T_Period>
86 try_lock_for(
const std::chrono::duration<T_Rep, T_Period>& timeout) noexcept
88 using namespace std::chrono;
157 k_mutex_init(&m_mutex);
202 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
211 template<
class T_Mutex>
213 : m_mutex_ptr(m.native_handle())
215 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
229 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
241 template<
class T_Mutex>
245 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
A recursive mutex CRTP base class.
constexpr mutex_base() noexcept
Protected default constructor so only derived objects can be created.
mutex_base & operator=(const mutex_base &)=delete
native_type const * native_const_pointer
auto try_lock_for(const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
Try locking the mutex with a timeout.
auto lock() noexcept
Lock the mutex. Wait forever until it is locked.
auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
mutex_base(mutex_base &&)=delete
auto unlock() noexcept
Unlock the mutex.
native_type * native_pointer
auto try_lock() noexcept
Try locking the mutex without waiting.
mutex_base & operator=(mutex_base &&)=delete
auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
mutex_base(const mutex_base &)=delete
struct k_mutex native_type
A recursive mutex class borrowing the native mutex.
constexpr mutex_ref & operator=(T_Mutex &m) noexcept
Assing another mutex object.
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
constexpr mutex_ref & operator=(native_pointer m) noexcept
Assing another mutex object.
constexpr mutex_ref(T_Mutex &m) noexcept
Construct a mutex using another mutex object.
constexpr mutex_ref(native_pointer m) noexcept
Construct a mutex using a native k_mutex*.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
mutex(const mutex &)=delete
mutex & operator=(mutex &&)=delete
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
mutex() noexcept
Default contructor.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
mutex & operator=(const mutex &)=delete
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