userver: engine::SharedMutex Class Reference
Loading...
Searching...
No Matches
engine::SharedMutex Class Referencefinal

std::shared_mutex replacement for asynchronous tasks More...

#include <userver/engine/shared_mutex.hpp>

Public Member Functions

 SharedMutex (const SharedMutex &)=delete
 
 SharedMutex (SharedMutex &&)=delete
 
SharedMutexoperator= (const SharedMutex &)=delete
 
SharedMutexoperator= (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)
 
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)
 

Detailed Description

std::shared_mutex replacement for asynchronous tasks

Example usage:

constexpr auto kTestString = "123";
std::string data;
{
std::lock_guard<engine::SharedMutex> lock(mutex);
// accessing the data under the mutex for writing
data = kTestString;
}
{
std::shared_lock<engine::SharedMutex> lock(mutex);
// accessing the data under the mutex for reading,
// data cannot be changed
const auto& x = data;
ASSERT_EQ(x, kTestString);
}
See also
Synchronization Primitives

Definition at line 23 of file shared_mutex.hpp.

Member Function Documentation

◆ try_lock_for()

template<typename Rep , typename Period >
bool engine::SharedMutex::try_lock_for ( const std::chrono::duration< Rep, Period > &  duration)

Definition at line 84 of file shared_mutex.hpp.

◆ try_lock_shared_for()

template<typename Rep , typename Period >
bool engine::SharedMutex::try_lock_shared_for ( const std::chrono::duration< Rep, Period > &  duration)

Definition at line 90 of file shared_mutex.hpp.

◆ try_lock_shared_until()

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

Definition at line 102 of file shared_mutex.hpp.

◆ try_lock_until()

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

Definition at line 96 of file shared_mutex.hpp.


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