The Gaudi Framework  master (37c0b60a)
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, typename = details::require_constructible_t<Value, Args...>>
 SynchronizedValue (Args &&... args)
 
 SynchronizedValue (const SynchronizedValue &rhs)
 
SynchronizedValueoperator= (const SynchronizedValue &rhs)
 
 SynchronizedValue (SynchronizedValue &&rhs)
 
SynchronizedValueoperator= (SynchronizedValue &&rhs)
 

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>>
class Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >

Definition at line 36 of file SynchronizedValue.h.

Constructor & Destructor Documentation

◆ SynchronizedValue() [1/3]

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, typename = details::require_constructible_t<Value, Args...>>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::SynchronizedValue ( Args &&...  args)
inline

Definition at line 43 of file SynchronizedValue.h.

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

◆ SynchronizedValue() [2/3]

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 ( const SynchronizedValue< Value, Mutex, ReadLock, WriteLock > &  rhs)
inline

Definition at line 45 of file SynchronizedValue.h.

45  {
46  static_assert( std::is_default_constructible_v<Value> ); // bound to hold, as otherwise we wouldn't get this
47  // far... so for 'documnentation purpose' really (C++20:
48  // turn into a `requires` clause )...
49  static_assert( std::is_copy_assignable_v<Value> );
50  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
51  m_obj = rhs.m_obj;
52  }

◆ SynchronizedValue() [3/3]

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 63 of file SynchronizedValue.h.

63  {
64  static_assert( std::is_default_constructible_v<Value> ); // bound to hold, as otherwise we wouldn't get this
65  // far... so for 'documnentation purpose' really (C++20:
66  // turn into a `requires` clause )...
67  static_assert( std::is_move_assignable_v<Value> );
68  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
69  m_obj = std::move( rhs.m_obj );
70  }

Member Function Documentation

◆ 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 54 of file SynchronizedValue.h.

54  {
55  static_assert( std::is_copy_assignable_v<Value> );
56  if ( this != &rhs ) {
57  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
58  m_obj = rhs.m_obj;
59  }
60  return *this;
61  }

◆ 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 72 of file SynchronizedValue.h.

72  {
73  static_assert( std::is_move_assignable_v<Value> );
74  if ( this != &rhs ) {
75  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
76  m_obj = std::move( rhs.m_obj );
77  }
78  return *this;
79  }

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 39 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 38 of file SynchronizedValue.h.


The documentation for this class was generated from the following file:
std::lock
T lock(T... args)
std::move
T move(T... args)
Gaudi::cxx::SynchronizedValue::m_mtx
Mutex m_mtx
Definition: SynchronizedValue.h:39
Gaudi::cxx::SynchronizedValue::m_obj
Value m_obj
Definition: SynchronizedValue.h:37
gaudirun.args
args
Definition: gaudirun.py:336