7 #ifndef ZPP_INCLUDE_ZPP_SYS_MUTEX_HPP
8 #define ZPP_INCLUDE_ZPP_SYS_MUTEX_HPP
10 #ifdef CONFIG_USERSPACE
12 #include <zephyr/kernel.h>
13 #include <zephyr/sys/__assert.h>
22 template<
typename T_Mutex>
41 [[nodiscard]]
bool lock() noexcept
71 template<
class T_Rep,
class T_Period>
73 try_lock_for(
const std::chrono::duration<T_Rep, T_Period>& timeout) noexcept
75 using namespace std::chrono;
133 sys_mutex_init(&m_mutex);
178 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
187 template<
class T_Mutex>
189 : m_mutex_ptr(m.native_handle())
191 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
203 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
213 template<
class T_Mutex>
217 __ASSERT_NO_MSG(m_mutex_ptr !=
nullptr);
bool lock() noexcept
Lock the mutex. Wait for ever until it is locked.
sys_mutex_base(const sys_mutex_base &)=delete
native_type * native_pointer
sys_mutex_base & operator=(sys_mutex_base &&)=delete
auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
bool unlock() noexcept
Unlock the mutex.
native_type const * native_cont_pointer
struct sys_mutex native_type
auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
bool try_lock() noexcept
Try locking the mutex without waiting.
constexpr sys_mutex_base() noexcept=default
Protected default contructor so only derived objects can be created.
bool try_lock_for(const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
Try locking the mutex with a timeout.
sys_mutex_base & operator=(const sys_mutex_base &)=delete
sys_mutex_base(sys_mutex_base &&)=delete
A recursive mutex class borrowing the native mutex.
constexpr sys_mutex_ref(T_Mutex &m) noexcept
Construct a mutex using a native sys_mutex*.
constexpr sys_mutex_ref & operator=(T_Mutex &m) noexcept
Construct a mutex using a native sys_mutex*.
constexpr sys_mutex_ref(native_pointer m) noexcept
Construct a mutex using a native sys_mutex*.
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
constexpr sys_mutex_ref & operator=(native_pointer m) noexcept
Construct a mutex using a native sys_mutex*.
constexpr auto native_handle() const noexcept -> native_const_pointer
get the native zephyr mutex handle.
sys_mutex & operator=(const sys_mutex &)=delete
sys_mutex(sys_mutex &&)=delete
sys_mutex(const sys_mutex &)=delete
sys_mutex() noexcept
Default constructor.
sys_mutex & operator=(sys_mutex &&)=delete
constexpr auto native_handle() noexcept -> native_pointer
get the native zephyr mutex handle.
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick