std::mutex replacement for asynchronous tasks
More...
#include <userver/engine/mutex.hpp>
|
| Mutex (const Mutex &)=delete |
|
| Mutex (Mutex &&)=delete |
|
Mutex & | operator= (const Mutex &)=delete |
|
Mutex & | operator= (Mutex &&)=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) |
|
std::mutex replacement for asynchronous tasks
Example usage:
constexpr std::string_view kTestData = "Test Data";
{
std::lock_guard<engine::Mutex>
lock(mutex);
const auto x = kTestData;
ASSERT_EQ(kTestData, x);
}
- See also
- Synchronization Primitives
Definition at line 26 of file mutex.hpp.
◆ lock()
void engine::Mutex::lock |
( |
| ) |
|
Locks the mutex. Blocks current coroutine if the mutex is locked by another coroutine.
- Note
- the behaviour is undefined if a coroutine tries to lock a mutex which is already locked by the current coroutine.
-
the method waits for the mutex even if the current task is cancelled.
◆ try_lock_for()
template<typename Rep , typename Period >
bool engine::Mutex::try_lock_for |
( |
const std::chrono::duration< Rep, Period > & |
duration | ) |
|
◆ try_lock_until()
template<typename Clock , typename Duration >
bool engine::Mutex::try_lock_until |
( |
const std::chrono::time_point< Clock, Duration > & |
until | ) |
|
◆ unlock()
void engine::Mutex::unlock |
( |
| ) |
|
Unlocks the mutex. The mutex must be locked by the current coroutine.
- Note
- the behaviour is undefined if a coroutine tries to unlock a mutex which is not locked or is locked by another coroutine
-
the order of coroutines to unblock is unspecified. Any code assuming any specific order (e.g. FIFO) is incorrect and must be fixed.
The documentation for this class was generated from the following file: