Go to the documentation of this file.
24 #ifndef RIOT_MUTEX_HPP
25 #define RIOT_MUTEX_HPP
31 #include <system_error>
50 inline constexpr
mutex() noexcept : m_mtx{{0}} {}
112 template <
class Mutex>
141 template <
class Mutex>
149 inline unique_lock() noexcept : m_mtx{
nullptr}, m_owns{
false} {}
165 : m_mtx{&mtx}, m_owns{mtx.try_lock()} {}
171 : m_mtx{&mtx}, m_owns{
true} {}
172 inline ~unique_lock() {
181 m_owns{
lock.m_owns} {
182 lock.m_mtx =
nullptr;
193 m_owns =
lock.m_owns;
194 lock.m_mtx =
nullptr;
218 std::swap(m_mtx,
lock.m_mtx);
219 std::swap(m_owns,
lock.m_owns);
239 inline bool owns_lock() const noexcept {
return m_owns; }
245 inline explicit operator bool() const noexcept {
return m_owns; }
260 template <
class Mutex>
262 if (m_mtx ==
nullptr) {
263 throw std::system_error(
264 std::make_error_code(std::errc::operation_not_permitted),
265 "References null mutex.");
268 throw std::system_error(
269 std::make_error_code(std::errc::resource_deadlock_would_occur),
276 template <
class Mutex>
278 if (m_mtx ==
nullptr) {
279 throw std::system_error(
280 std::make_error_code(std::errc::operation_not_permitted),
281 "References null mutex.");
284 throw std::system_error(
285 std::make_error_code(std::errc::resource_deadlock_would_occur),
288 m_owns = m_mtx->try_lock();
292 template <
class Mutex>
295 throw std::system_error(
296 std::make_error_code(std::errc::operation_not_permitted),
297 "Mutex not locked.");
308 template <
class Mutex>
315 #endif // RIOT_MUTEX_HPP
bool owns_lock() const noexcept
Query ownership of the associate mutex.
native_handle_type native_handle()
Provides access to the native handle.
unique_lock & operator=(unique_lock &&lock) noexcept
Move assignment operator.
mutex_type * release() noexcept
Disassociate this lock from its mutex.
C++11 compliant implementation of unique lock.
Tag type for adopt lock strategy.
lock_guard(mutex_type &mtx)
Constructs a lock_gurad from a Mutex and locks it.
unique_lock(mutex_type &mtx, adopt_lock_t)
Constructs a unique_lock from a Mutex that is already owned by the thread.
void lock()
Lock the mutex.
constexpr defer_lock_t defer_lock
Tag constant for defer lock strategy.
lock_guard(mutex_type &mtx, adopt_lock_t)
Constructs a lock_guard from a Mutex, acquireing ownership without locking it.
constexpr adopt_lock_t adopt_lock
Tag constant for adopt lock strategy.
Mutex struct within mqtt paho.
bool try_lock() noexcept
Try to lock the mutex.
Mutex mutex_type
The type of Mutex used by the lock.
void swap(unique_lock< Mutex > &lhs, unique_lock< Mutex > &rhs) noexcept
Swaps two mutexes.
C++11 compliant implementation of unique lock.
void unlock() noexcept
Unlock the mutex.
unique_lock(unique_lock &&lock) noexcept
Move constructor.
void unlock()
Unlocks the associated mutex.
mutex_t lock
MQTT thread mutex.
unique_lock(mutex_type &mtx, try_to_lock_t)
Constructs a unique_lock from a Mutex and tries to lock it.
unique_lock(mutex_type &mtx)
Constructs a unique_lock from a Mutex and locks it.
bool try_lock()
Tries to lock the associated mutex.
Mutex for thread synchronization.
unique_lock(mutex_type &mtx, defer_lock_t) noexcept
Constructs a unique_lock from a Mutex but does not lock it.
C++11 compliant implementation of mutex, uses the time point implemented in our chrono replacement in...
void swap(unique_lock &lock) noexcept
Swap this unique_lock with another unique_lock.
void lock()
Locks the associated mutex.
constexpr try_to_lock_t try_to_lock
Tag constant for try lock strategy.
mutex_type * mutex() const noexcept
Provides access to the associated mutex.
Tag type for defer lock strategy.
Tag type for try lock strategy.
Mutex mutex_type
The type of Mutex used by the lock_guard.