3#ifndef TETL_MUTEX_UNIQUE_LOCK_HPP
4#define TETL_MUTEX_UNIQUE_LOCK_HPP
27template <
typename Mutex>
30 Mutex* _mutex{
nullptr};
79 template <
typename Clock,
typename Duration>
91 template <
typename Rep,
typename Period>
107 : _mutex{
exchange(u._mutex,
nullptr)}
117 if (_mutex !=
nullptr && _owns) {
120 _mutex =
exchange(u._mutex,
nullptr);
128 constexpr auto lock() noexcept(noexcept(_mutex->
lock())) ->
void
130 if ((_mutex !=
nullptr) and !_owns) {
142 if ((_mutex !=
nullptr) && !_owns) {
143 if (
auto success = _mutex->try_lock(); success) {
159 template <
typename Rep,
typename Period>
163 if ((_mutex !=
nullptr) && !_owns) {
164 if (
auto success = _mutex->try_lock_for(dur); success) {
174 template <
typename Clock,
typename Duration>
176 noexcept(
noexcept(_mutex->try_lock_until(tp))) ->
bool
178 if ((_mutex !=
nullptr) && !_owns) {
179 if (
auto success = _mutex->try_lock_until(tp); success) {
192 if ((_mutex !=
nullptr) and _owns) {
202 swap(_mutex, other._mutex);
203 swap(_owns, other._owns);
220 [[nodiscard]]
constexpr auto owns_lock() const noexcept ->
bool {
return _owns; }
223 [[nodiscard]]
explicit constexpr operator bool() const noexcept {
return owns_lock(); }
Definition adjacent_find.hpp:8
constexpr auto exchange(T &obj, U &&newValue) noexcept(etl::is_nothrow_move_constructible_v< T > and etl::is_nothrow_assignable_v< T &, U >) -> T
Replaces the value of obj with new_value and returns the old value of obj.
Definition exchange.hpp:16
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249
Empty struct tag types used to specify locking strategy for etl::lock_guard, etl::scoped_lock,...
Definition tags.hpp:41
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:31
Class template time_point represents a point in time. It is implemented as if it stores a value of ty...
Definition time_point.hpp:21
Empty struct tag types used to specify locking strategy for etl::lock_guard, etl::scoped_lock,...
Definition tags.hpp:13
Empty struct tag types used to specify locking strategy for etl::lock_guard, etl::scoped_lock,...
Definition tags.hpp:27
constexpr unique_lock(unique_lock const &)=delete
Deleted copy constructor. unique_lock is move only.
constexpr unique_lock(mutex_type &m, adopt_lock_t)
Constructs a unique_lock with m as the associated mutex. Additionally: Assumes the calling thread alr...
Definition unique_lock.hpp:68
constexpr auto mutex() const noexcept -> mutex_type *
Returns a pointer to the associated mutex, or a null pointer if there is no associated mutex.
Definition unique_lock.hpp:227
constexpr auto swap(unique_lock &other) noexcept -> void
Exchanges the internal states of the lock objects.
Definition unique_lock.hpp:199
constexpr auto owns_lock() const noexcept -> bool
Checks whether *this owns a locked mutex or not.
Definition unique_lock.hpp:220
constexpr auto operator=(unique_lock &&u) noexcept -> unique_lock &
Move assignment operator. Replaces the contents with those of other using move semantics....
Definition unique_lock.hpp:115
constexpr auto try_lock_until(chrono::time_point< Clock, Duration > const &tp) noexcept(noexcept(_mutex->try_lock_until(tp))) -> bool
Tries to lock (i.e., takes ownership of) the associated mutex without blocking.
Definition unique_lock.hpp:175
constexpr auto operator=(unique_lock const &) -> unique_lock &=delete
Deleted copy assignment. unique_lock is move only.
constexpr auto release() noexcept -> mutex_type *
Breaks the association of the associated mutex, if any, and *this. No locks are unlocked....
Definition unique_lock.hpp:213
constexpr auto lock() noexcept(noexcept(_mutex->lock())) -> void
Locks (i.e., takes ownership of) the associated mutex.
Definition unique_lock.hpp:128
constexpr auto unlock() -> void
Unlocks (i.e., releases ownership of) the associated mutex and releases ownership....
Definition unique_lock.hpp:190
constexpr unique_lock(mutex_type &m, chrono::time_point< Clock, Duration > const &absTime) noexcept
Constructs a unique_lock with m as the associated mutex. Additionally: Tries to lock the associated m...
Definition unique_lock.hpp:80
constexpr unique_lock(mutex_type &m, defer_lock_t) noexcept
Constructs a unique_lock with m as the associated mutex. Additionally: Does not lock the associated m...
Definition unique_lock.hpp:51
constexpr auto try_lock_for(chrono::duration< Rep, Period > const &dur) noexcept(noexcept(_mutex->try_lock_for(dur))) -> bool
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified timeout_duratio...
Definition unique_lock.hpp:160
constexpr ~unique_lock() noexcept
Definition unique_lock.hpp:125
friend constexpr auto swap(unique_lock &lhs, unique_lock &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
Specializes the swap algorithm for unique_lock. Exchanges the state of lhs with that of rhs.
Definition unique_lock.hpp:230
constexpr auto try_lock() noexcept(noexcept(_mutex->try_lock())) -> bool
Tries to lock (i.e., takes ownership of) the associated mutex without blocking.
Definition unique_lock.hpp:140
constexpr unique_lock(mutex_type &m, try_to_lock_t) noexcept
Constructs a unique_lock with m as the associated mutex. Additionally: Tries to lock the associated m...
Definition unique_lock.hpp:60
constexpr unique_lock() noexcept=default
Constructs a unique_lock with no associated mutex.
constexpr unique_lock(mutex_type &m, chrono::duration< Rep, Period > const &relTime) noexcept
Constructs a unique_lock with m as the associated mutex. Additionally: Tries to lock the associated m...
Definition unique_lock.hpp:92
constexpr unique_lock(unique_lock &&u) noexcept
Move constructor. Initializes the unique_lock with the contents of other. Leaves other with no associ...
Definition unique_lock.hpp:106
Mutex mutex_type
Definition unique_lock.hpp:34