14#ifndef BOOST_FAIRNESS_SHARED_LOCK_HPP
15#define BOOST_FAIRNESS_SHARED_LOCK_HPP
19#include <system_error>
37 template<
typename Lockable>
59 throw_operation_not_permitted_();
108 : lockable_(std::addressof(m)), lockOwned_(
true), currentPriority_(p)
121 template<
typename Clock,
typename Duration>
123 : lockable_(std::addressof(m)),
124 lockOwned_(lockable_->try_lock_shared_until(atime, p)),
127 currentPriority_ = p;
140 template<
typename Rep,
typename Period>
142 : lockable_(std::addressof(m)),
143 lockOwned_(lockable_->try_lock_shared_for(rtime, p)),
146 currentPriority_ = p;
155 lockable_->unlock_shared();
179 : lockable_(other.lockable_), lockOwned_(other.lockOwned_), currentPriority_(other.currentPriority_){
181 other.lockOwned_ =
false;
197 other.lockOwned_ =
false;
208 std::swap(lockable_, other.lockable_);
209 std::swap(lockOwned_, other.lockOwned_);
210 std::swap(currentPriority_, other.currentPriority_);
221 Lockable* __ret = lockable_;
236 {
return lockOwned_; }
244 {
return currentPriority_; }
253 explicit operator bool() const noexcept
271 {
return lockable_; }
288 throw_operation_not_permitted_();
290 throw_resource_deadlock_would_occur_();
293 lockable_->lock_shared(p);
295 currentPriority_ = p;
310 throw_operation_not_permitted_();
312 throw_resource_deadlock_would_occur_();
315 lockOwned_ = lockable_->try_lock_shared(p);
317 currentPriority_ = p;
336 throw_operation_not_permitted_();
339 lockable_->unlock_shared();
366 template<
typename Clock,
typename Duration>
369 throw_operation_not_permitted_();
371 throw_resource_deadlock_would_occur_();
374 lockOwned_ = lockable_->try_lock_shared_until(atime, p);
376 currentPriority_ = p;
405 template<
typename Rep,
typename Period>
408 throw_operation_not_permitted_();
410 throw_resource_deadlock_would_occur_();
413 lockOwned_ = lockable_->try_lock_shared_for(rtime, p);
415 currentPriority_ = p;
426 static inline void throw_operation_not_permitted_(){
427 throw std::system_error(std::make_error_code(std::errc::operation_not_permitted));
434 static inline void throw_resource_deadlock_would_occur_(){
435 throw std::system_error(std::make_error_code(std::errc::resource_deadlock_would_occur));
444 template<
typename Lockable>
Empty types used by unique_lock and shared_lock constructors.
The class shared_lock is a general-purpose shared mutex ownership wrapper allowing deferred locking,...
Definition shared_lock.hpp:38
Lockable * mutex() const noexcept
Returns a pointer to the associated mutex, or a null pointer if there is no associated mutex.
Definition shared_lock.hpp:270
Lockable * release() noexcept
Breaks the association of the associated mutex, if any, and *this. No locks are unlocked....
Definition shared_lock.hpp:220
void unlock()
Unlocks the associated mutex from shared mode. Effectively calls mutex()->unlock_shared()....
Definition shared_lock.hpp:334
bool try_lock(Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock the associated mutex in shared mode without blocking. Effectively calls mutex()->try_lo...
Definition shared_lock.hpp:308
bool owns_lock() const noexcept
Checks whether *this owns a locked mutex or not.
Definition shared_lock.hpp:235
bool try_lock_for(const std::chrono::duration< Rep, Period > &rtime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock the associated mutex in shared mode. Blocks until specified rtime has elapsed or the lo...
Definition shared_lock.hpp:406
void swap(shared_lock &other) noexcept
Exchanges the internal states of the lock objects.
Definition shared_lock.hpp:207
void lock(Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Locks the associated mutex in shared mode. Effectively calls mutex()->lock_shared().
Definition shared_lock.hpp:286
Priority_t lock_priority() const noexcept
Checks the current priority of *this. #TODO.
Definition shared_lock.hpp:243
bool try_lock_until(const std::chrono::time_point< Clock, Duration > &atime, Priority_t const p=BOOST_FAIRNESS_MINIMUM_PRIORITY)
Tries to lock the associated mutex in shared mode. Blocks until specified atime has been reached or t...
Definition shared_lock.hpp:367
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