userver: engine::SingleWaitingTaskMutex Class Reference
No Matches
engine::SingleWaitingTaskMutex Class Referencefinal

#include <userver/engine/single_waiting_task_mutex.hpp>

Detailed Description

Lighter version of Mutex with not more than 1 waiting task.

There are some situations when a resource is accessed concurrently, but concurrency factor is limited by 2. For instance: implications of socket r/w duality.

Ignores task cancellations (succeeds even if the current task is cancelled).

Example usage:

The class's API is the same as of engine::Mutex:

constexpr std::string_view kTestData = "Test Data";
std::lock_guard<engine::Mutex> lock(mutex);
// accessing data under a mutex
const auto x = kTestData;
ASSERT_EQ(kTestData, x);
See also
Synchronization Primitives

Definition at line 34 of file single_waiting_task_mutex.hpp.

Public Member Functions

 SingleWaitingTaskMutex (const SingleWaitingTaskMutex &)=delete
 SingleWaitingTaskMutex (SingleWaitingTaskMutex &&)=delete
SingleWaitingTaskMutexoperator= (const SingleWaitingTaskMutex &)=delete
SingleWaitingTaskMutexoperator= (SingleWaitingTaskMutex &&)=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)

Member Function Documentation

◆ lock()

void engine::SingleWaitingTaskMutex::lock ( )

Locks the mutex. Blocks current coroutine if the mutex is locked by another coroutine.

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::SingleWaitingTaskMutex::try_lock_for ( const std::chrono::duration< Rep, Period > & duration)

Definition at line 73 of file single_waiting_task_mutex.hpp.

◆ try_lock_until()

template<typename Clock , typename Duration >
bool engine::SingleWaitingTaskMutex::try_lock_until ( const std::chrono::time_point< Clock, Duration > & until)

Definition at line 79 of file single_waiting_task_mutex.hpp.

◆ unlock()

void engine::SingleWaitingTaskMutex::unlock ( )

Unlocks the mutex. Before calling this method the mutex should be locked by the current coroutine.

The documentation for this class was generated from the following file: