userver: concurrent::ItemMutex< Key, Equal > Class Template Reference
Loading...
Searching...
No Matches
concurrent::ItemMutex< Key, Equal > Class Template Referencefinal

#include <userver/concurrent/mutex_set.hpp>

Detailed Description

template<typename Key, typename Equal>
class concurrent::ItemMutex< Key, Equal >

Mutex-like object associated with the key of a MutexSet. It provides the same interface as engine::Mutex, you may use it with std::unique_lock, std::lock_guard, etc.

Note
different ItemMutex'es of the same MutexSet obtained with the same argument to GetMutexForKey() share the same critical section. IOW, if the first mutex is locked, the second one will block until the first mutex is unlocked.
can be used only from coroutines.

Definition at line 46 of file mutex_set.hpp.

Public Types

using HashAndKey = utils::CachedHash<Key>
 
using MutexDatum = impl::MutexDatum<HashAndKey, utils::CachedHashKeyEqual<Equal>>
 

Public Member Functions

 ItemMutex (MutexDatum &md, HashAndKey &&key)
 
void lock ()
 
void unlock ()
 
bool try_lock ()
 
template<typename Rep , typename Period >
bool try_lock_for (std::chrono::duration< Rep, Period >)
 
template<typename Clock , typename Duration >
bool try_lock_until (std::chrono::time_point< Clock, Duration >)
 

Member Typedef Documentation

◆ HashAndKey

template<typename Key , typename Equal >
using concurrent::ItemMutex< Key, Equal >::HashAndKey = utils::CachedHash<Key>

Definition at line 48 of file mutex_set.hpp.

◆ MutexDatum

template<typename Key , typename Equal >
using concurrent::ItemMutex< Key, Equal >::MutexDatum = impl::MutexDatum<HashAndKey, utils::CachedHashKeyEqual<Equal>>

Definition at line 50 of file mutex_set.hpp.

Constructor & Destructor Documentation

◆ ItemMutex()

template<typename Key , typename Equal >
concurrent::ItemMutex< Key, Equal >::ItemMutex ( MutexDatum & md,
HashAndKey && key )

Definition at line 115 of file mutex_set.hpp.

Member Function Documentation

◆ lock()

template<typename Key , typename Equal >
void concurrent::ItemMutex< Key, Equal >::lock ( )

Definition at line 118 of file mutex_set.hpp.

◆ try_lock()

template<typename Key , typename Equal >
bool concurrent::ItemMutex< Key, Equal >::try_lock ( )

Definition at line 151 of file mutex_set.hpp.

◆ try_lock_for()

template<typename Key , typename Equal >
template<typename Rep , typename Period >
bool concurrent::ItemMutex< Key, Equal >::try_lock_for ( std::chrono::duration< Rep, Period > duration)

Definition at line 158 of file mutex_set.hpp.

◆ try_lock_until()

template<typename Key , typename Equal >
template<typename Clock , typename Duration >
bool concurrent::ItemMutex< Key, Equal >::try_lock_until ( std::chrono::time_point< Clock, Duration > time_point)

Definition at line 165 of file mutex_set.hpp.

◆ unlock()

template<typename Key , typename Equal >
void concurrent::ItemMutex< Key, Equal >::unlock ( )

Definition at line 127 of file mutex_set.hpp.


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