#include <userver/engine/shared_mutex.hpp>
std::shared_mutex replacement for asynchronous tasks.
Ignores task cancellations (succeeds even if the current task is cancelled).
Writers (unique locks) have priority over readers (shared locks), thus new shared lock waits for the pending writes to finish, which in turn waits for existing existing shared locks to unlock first.
Definition at line 29 of file shared_mutex.hpp.
Public Member Functions | |
SharedMutex (const SharedMutex &)=delete | |
SharedMutex (SharedMutex &&)=delete | |
SharedMutex & | operator= (const SharedMutex &)=delete |
SharedMutex & | operator= (SharedMutex &&)=delete |
void | lock () |
void | unlock () |
bool | try_lock () |
template<typename Rep , typename Period > | |
bool | try_lock_for (const std::chrono::duration< Rep, Period > &) |
template<typename Clock , typename Duration > | |
bool | try_lock_until (const std::chrono::time_point< Clock, Duration > &) |
bool | try_lock_until (Deadline deadline) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | lock_shared () |
void | unlock_shared () |
bool | try_lock_shared () |
template<typename Rep , typename Period > | |
bool | try_lock_shared_for (const std::chrono::duration< Rep, Period > &) |
template<typename Clock , typename Duration > | |
bool | try_lock_shared_until (const std::chrono::time_point< Clock, Duration > &) |
bool | try_lock_shared_until (Deadline deadline) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void engine::SharedMutex::lock | ( | ) |
Locks the mutex for unique ownership. Blocks current coroutine if the mutex is locked by another coroutine for reading or writing.
void engine::SharedMutex::lock_shared | ( | ) |
Locks the mutex for shared ownership. Blocks current coroutine if the mutex is locked by another coroutine for reading or writing.
bool engine::SharedMutex::try_lock | ( | ) |
Tries to lock the mutex for unique ownership without blocking the coroutine, returns true if succeeded.
bool engine::SharedMutex::try_lock_for | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
Tries to lock the mutex for unique ownership in specified duration. Blocks current coroutine if the mutex is locked by another coroutine up to the provided duration.
Definition at line 142 of file shared_mutex.hpp.
bool engine::SharedMutex::try_lock_shared | ( | ) |
Tries to lock the mutex for shared ownership without blocking the coroutine, returns true if succeeded.
bool engine::SharedMutex::try_lock_shared_for | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
Tries to lock the mutex for shared ownership in specified duration. Blocks current coroutine if the mutex is locked by another coroutine up to the provided duration.
Definition at line 148 of file shared_mutex.hpp.
bool engine::SharedMutex::try_lock_shared_until | ( | const std::chrono::time_point< Clock, Duration > & | until | ) |
Tries to lock the mutex for shared ownership till specified time point. Blocks current coroutine if the mutex is locked by another coroutine up to the provided duration.
Definition at line 160 of file shared_mutex.hpp.
bool engine::SharedMutex::try_lock_until | ( | const std::chrono::time_point< Clock, Duration > & | until | ) |
Tries to lock the mutex for unique ownership till specified time point. Blocks current coroutine if the mutex is locked by another coroutine up to the provided duration.
Definition at line 154 of file shared_mutex.hpp.
void engine::SharedMutex::unlock | ( | ) |
Unlocks the mutex for unique ownership. Before calling this method the the mutex should be locked for unique ownership by current coroutine.
void engine::SharedMutex::unlock_shared | ( | ) |
Unlocks the mutex for shared ownership. Before calling this method the mutex should be locked for shared ownership by current coroutine.