Your opinion will help to improve our service
Leave a feedback >#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 () |
Tries to lock the mutex for unique ownership without blocking the task, returns true if succeeded. | |
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 task if the mutex is locked by another task for reading or writing.
void engine::SharedMutex::lock_shared | ( | ) |
Locks the mutex for shared ownership. Blocks current task if the mutex is locked by another task for reading or writing.
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 task if the mutex is locked by another task up to the provided duration.
Definition at line 132 of file shared_mutex.hpp.
bool engine::SharedMutex::try_lock_shared | ( | ) |
Tries to lock the mutex for shared ownership without blocking the task, 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 task if the mutex is locked by another task up to the provided duration.
Definition at line 137 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 task if the mutex is locked by another task up to the provided duration.
Definition at line 147 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 task if the mutex is locked by another task up to the provided duration.
Definition at line 142 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 task.
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 task.