13#ifndef BOOST_FAIRNESS_UNIQUE_LOCK_HPP
14#define BOOST_FAIRNESS_UNIQUE_LOCK_HPP
17#include <system_error>
34 template <
typename Lockable>
55 throw_operation_not_permitted_();
100 : lockable_(std::addressof(m)), lockOwned_(
true), currentPriority_(p)
123 template <
typename Clock,
typename Duration>
125 : lockable_(std::addressof(m)),
129 currentPriority_ = p;
141 template <
typename Rep,
typename Period>
143 : lockable_(std::addressof(m)),
147 currentPriority_ = p;
167 : lockable_(other.lockable_), lockOwned_(other.lockOwned_), currentPriority_(other.currentPriority_){
169 other.lockOwned_ =
false;
188 throw_operation_not_permitted_();
190 throw_resource_deadlock_would_occur_();
195 currentPriority_ = p;
217 throw_operation_not_permitted_();
219 throw_resource_deadlock_would_occur_();
222 lockOwned_ = lockable_->try_lock(p);
224 currentPriority_ = p;
244 throw_operation_not_permitted_();
275 template <
typename Clock,
typename Duration>
278 throw_operation_not_permitted_();
280 throw_resource_deadlock_would_occur_();
283 lockOwned_ = lockable_->try_lock_until(atime, p);
285 currentPriority_ = p;
312 template <
typename Rep,
typename Period>
315 throw_operation_not_permitted_();
317 throw_resource_deadlock_would_occur_();
320 lockOwned_ = lockable_->try_lock_for(rtime);
322 currentPriority_ = p;
338 other.lockOwned_ =
false;
350 std::swap(lockable_, other.lockable_);
351 std::swap(lockOwned_, other.lockOwned_);
352 std::swap(currentPriority_, other.currentPriority_);
364 Lockable *__ret = lockable_;
378 {
return lockOwned_; }
386 {
return currentPriority_; }
394 explicit operator bool() const noexcept
411 {
return lockable_; }
418 static inline void throw_operation_not_permitted_()
419 {
throw std::system_error(std::make_error_code(std::errc::operation_not_permitted)); }
425 static inline void throw_resource_deadlock_would_occur_()
426 {
throw std::system_error(std::make_error_code(std::errc::resource_deadlock_would_occur)); }
440 template <
typename Lockable>
The class unique_lock is a general-purpose mutex ownership wrapper allowing deferred locking,...
Definition unique_lock.hpp:35
unique_lock(const unique_lock &)=delete
unique_lock & operator=(unique_lock &&other) noexcept
Definition unique_lock.hpp:333
unique_lock(Lockable &m, const std::chrono::duration< Rep, Period > &rtime, Priority_t p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Construct a new unique lock object.
Definition unique_lock.hpp:142
void unlock()
Unlocks (i.e., releases ownership of) the associated mutex and releases ownership....
Definition unique_lock.hpp:242
bool try_lock(Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock (i.e., takes ownership of) the associated mutex without blocking. Effectively calls mut...
Definition unique_lock.hpp:215
unique_lock & operator=(const unique_lock &)=delete
Lockable * mutex() const noexcept
Definition unique_lock.hpp:410
bool try_lock_for(const std::chrono::duration< Rep, Period > &rtime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified rtime has elaps...
Definition unique_lock.hpp:313
void lock(Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Locks the associated mutex. Effectively calls mutex()->lock().
Definition unique_lock.hpp:186
bool owns_lock() const noexcept
Checks whether *this owns a locked mutex or not.
Definition unique_lock.hpp:377
unique_lock(unique_lock &&other) noexcept
Construct a new unique lock object.
Definition unique_lock.hpp:166
unique_lock(Lockable &m, Priority_t const p, adopt_lock_t) noexcept
Construct a new unique lock object.
Definition unique_lock.hpp:99
unique_lock(Lockable &m, const std::chrono::time_point< Clock, Duration > &atime, Priority_t p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Construct a new unique lock object.
Definition unique_lock.hpp:124
unique_lock(Lockable &m, try_to_lock_t)
Construct a new unique lock object.
Definition unique_lock.hpp:87
void swap(unique_lock &other) noexcept
Exchanges the internal states of the lock objects.
Definition unique_lock.hpp:349
Priority_t lock_priority() const noexcept
TODO.
Definition unique_lock.hpp:385
unique_lock(Lockable &m, defer_lock_t) noexcept
Construct a new unique lock object.
Definition unique_lock.hpp:66
unique_lock(Lockable &m, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Construct a new unique lock object.
Definition unique_lock.hpp:52
unique_lock() noexcept
Construct a new unique lock object.
Definition unique_lock.hpp:42
bool try_lock_until(const std::chrono::time_point< Clock, Duration > &atime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock (i.e., takes ownership of) the associated mutex. Blocks until specified atime has been ...
Definition unique_lock.hpp:276
unique_lock(Lockable &m, Priority_t const p, try_to_lock_t)
Construct a new unique lock object.
Definition unique_lock.hpp:76
~unique_lock()
Destroy the unique lock object.
Definition unique_lock.hpp:154
Lockable * release() noexcept
Breaks the association of the associated mutex, if any, and *this. No locks are unlocked....
Definition unique_lock.hpp:363
Definition acquisition_modes.hpp:16
uint8_t Priority_t
Definition priority_t.hpp:17
bool is_valid_priority(Priority_t const p)
allows you to verify that an input priority is valid. Has to be in the range [BOOST_FAIRNESS_MINIMUM_...
Definition priority_t.hpp:45
void swap(shared_lock< Lockable > &lhs, shared_lock< Lockable > &rhs) noexcept
Definition shared_lock.hpp:445
Alias the type Priority_t. Priority_t is the type of priorities that are used by the priority_mutexes...
#define BOOST_FAIRNESS_MINIMUM_PRIORITY
Priorities are indexes in an array, that means that if I define a priority_mutex<BOOST_FAIRNESS_MAXIM...
Definition priority_t.hpp:36
#define BOOST_FAIRNESS_INVALID_PRIORITY
A number indicating an invalid priority which is not usable by the mutexes.
Definition priority_t.hpp:29