The Gaudi Framework  master (bb95dfce)
Loading...
Searching...
No Matches
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock > Class Template Reference

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/cxx/SynchronizedValue.h>

Collaboration diagram for Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >:

Public Member Functions

template<typename... Args>
 explicit (sizeof...(Args)==1) SynchronizedValue(Args &&... args)
 SynchronizedValue (SynchronizedValue const &rhs)
SynchronizedValueoperator= (const SynchronizedValue &rhs)
 SynchronizedValue (SynchronizedValue &&rhs)
SynchronizedValueoperator= (SynchronizedValue &&rhs)
template<typename... Args, std::invocable< Value &, Args... > F>
decltype(auto) with_lock (F &&f, Args &&... args)
template<typename... Args, std::invocable< const Value &, Args... > F>
decltype(auto) with_lock (F &&f, Args &&... args) const

Private Attributes

Value m_obj
Mutex m_mtx

Detailed Description

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
requires ( !std::is_reference_v<Value> )
class Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >

Definition at line 31 of file SynchronizedValue.h.

Constructor & Destructor Documentation

◆ SynchronizedValue() [1/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::SynchronizedValue ( SynchronizedValue< Value, Mutex, ReadLock, WriteLock > const & rhs)
inline

Definition at line 41 of file SynchronizedValue.h.

◆ SynchronizedValue() [2/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::SynchronizedValue ( SynchronizedValue< Value, Mutex, ReadLock, WriteLock > && rhs)
inline

Definition at line 58 of file SynchronizedValue.h.

60 : m_obj( [&] {
61 auto _ = WriteLock{ rhs.m_mtx };
62 return Value( std::move( rhs.m_obj ) );
63 }() ) {}

Member Function Documentation

◆ explicit()

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
template<typename... Args>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::explicit ( sizeof... Args = = 1) &&
inline

Definition at line 39 of file SynchronizedValue.h.

39: m_obj( std::forward<Args>( args )... ) {}

◆ operator=() [1/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
SynchronizedValue & Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::operator= ( const SynchronizedValue< Value, Mutex, ReadLock, WriteLock > & rhs)
inline

Definition at line 48 of file SynchronizedValue.h.

50 {
51 if ( this != &rhs ) {
52 auto _ = std::scoped_lock{ rhs.m_mtx, m_mtx };
53 m_obj = rhs.m_obj;
54 }
55 return *this;
56 }

◆ operator=() [2/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
SynchronizedValue & Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::operator= ( SynchronizedValue< Value, Mutex, ReadLock, WriteLock > && rhs)
inline

Definition at line 65 of file SynchronizedValue.h.

67 {
68 if ( this != &rhs ) {
69 auto _ = std::scoped_lock{ rhs.m_mtx, m_mtx };
71 }
72 return *this;
73 }

◆ with_lock() [1/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
template<typename... Args, std::invocable< Value &, Args... > F>
decltype(auto) Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::with_lock ( F && f,
Args &&... args )
inline

Definition at line 77 of file SynchronizedValue.h.

77 {
78 auto _ = WriteLock{ m_mtx };
80 }

◆ with_lock() [2/2]

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
template<typename... Args, std::invocable< const Value &, Args... > F>
decltype(auto) Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::with_lock ( F && f,
Args &&... args ) const
inline

Definition at line 83 of file SynchronizedValue.h.

83 {
84 auto _ = ReadLock{ m_mtx };
86 }

Member Data Documentation

◆ m_mtx

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
Mutex Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::m_mtx
mutableprivate

Definition at line 33 of file SynchronizedValue.h.

◆ m_obj

template<typename Value, typename Mutex = std::mutex, typename ReadLock = std::conditional_t<std::is_same_v<std::shared_mutex, Mutex>, std::shared_lock<Mutex>, std::lock_guard<Mutex>>, typename WriteLock = std::lock_guard<Mutex>>
Value Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::m_obj
private

Definition at line 32 of file SynchronizedValue.h.


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