Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (e199b415)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
 requires (std::is_constructible_v< Value, Args... >) SynchronizedValue(Args &&... args)
 
 SynchronizedValue (const SynchronizedValue &rhs)
 
SynchronizedValueoperator= (const SynchronizedValue &rhs)
 
 SynchronizedValue (SynchronizedValue &&rhs)
 
SynchronizedValueoperator= (SynchronizedValue &&rhs)
 
template<typename... Args, std::invocable< Value &, Args... > F>
 requires (!std::is_invocable_v< F, const Value &, Args... >) decltype(auto) with_lock(F &&f
 
return std::invoke (std::forward< F >(f), m_obj, std::forward< Args >(args)...)
 

Public Attributes

Args && args
 

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

Definition at line 39 of file SynchronizedValue.h.

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

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

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

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

48  {
49  static_assert( std::is_copy_assignable_v<Value> );
50  if ( this != &rhs ) {
51  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
52  m_obj = rhs.m_obj;
53  }
54  return *this;
55  }

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

66  {
67  static_assert( std::is_move_assignable_v<Value> );
68  if ( this != &rhs ) {
69  auto lock = std::scoped_lock{ rhs.m_mtx, m_mtx };
70  m_obj = std::move( rhs.m_obj );
71  }
72  return *this;
73  }

◆ requires() [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>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::requires ( !std::is_invocable_v< F, const Value &, Args... >  ) &&

◆ requires() [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>
Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::requires ( std::is_constructible_v< Value, Args... >  ) &&
inline

Definition at line 36 of file SynchronizedValue.h.

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

◆ std::invoke()

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>>
return Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::std::invoke ( std::forward< F >  f,
m_obj  ,
std::forward< Args >(args ... 
)

Member Data Documentation

◆ args

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>>
Args&& Gaudi::cxx::SynchronizedValue< Value, Mutex, ReadLock, WriteLock >::args
Initial value:
{
WriteLock _{ m_mtx }

Definition at line 77 of file SynchronizedValue.h.

◆ 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 32 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 31 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::args
Args && args
Definition: SynchronizedValue.h:77
Gaudi::cxx::SynchronizedValue::m_mtx
Mutex m_mtx
Definition: SynchronizedValue.h:32
Gaudi::cxx::SynchronizedValue::m_obj
Value m_obj
Definition: SynchronizedValue.h:30