#include <userver/engine/mutex.hpp>
std::mutex replacement for asynchronous tasks.
Ignores task cancellations (succeeds even if the current task is cancelled).
Public Member Functions | |
Mutex (const Mutex &)=delete | |
Mutex (Mutex &&)=delete | |
Mutex & | operator= (const Mutex &)=delete |
Mutex & | operator= (Mutex &&)=delete |
void | lock () |
void | unlock () |
bool | try_lock () noexcept |
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 engine::Mutex::lock | ( | ) |
Locks the mutex. Blocks current coroutine if the mutex is locked by another coroutine. Throws if a coroutine tries to lock a mutex which is already locked by the current coroutine.
|
noexcept |
Tries to lock the mutex without blocking the coroutine, returns true if succeeded.
bool engine::Mutex::try_lock_for | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
Tries to lock the mutex in specified duration. Blocks current coroutine if the mutex is locked by another coroutine up to the provided duration. Throws if a coroutine tries to lock a mutex which is already locked by the current coroutine.
bool engine::Mutex::try_lock_until | ( | const std::chrono::time_point< Clock, Duration > & | until | ) |
Tries to lock the mutex till specified time point. Blocks current coroutine if the mutex is locked by another coroutine up to the provided time point. Throws if a coroutine tries to lock a mutex which is already locked by the current coroutine.
void engine::Mutex::unlock | ( | ) |
Unlocks the mutex. Before calling this method the mutex should be locked by the current coroutine.