JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches

template class that wraps any datatype and combines it with a mutex, exposes the lock()/unlock() interface, so access to the contained data can be synchronized More...

#include <jkqtpconcurrencytools.h>

Inheritance diagram for JKQTPSynchronized< T >:
[legend]
Collaboration diagram for JKQTPSynchronized< T >:
[legend]

Classes

struct  AdoptLockType
 type of AdoptLock tag, which is used in ReadLocker and WriteLocker to adopt a pre-locked JKQTPSynchronized<T> More...
 
class  ReadLocker
 type of a lock_guard for a JKQTPSynchronized<T> for reading More...
 
class  WriteLocker
 type of a lock_guard for a JKQTPSynchronized<T> for writing More...
 

Public Types

typedef T data_type
 contained data type T
 
typedef JKQTPSynchronized< T >::WriteLocker Locker
 type of a lock_guard for a JKQTPSynchronized<T> for writing
 
typedef QReadWriteLock MutexType
 Mutex used by this temmplate.
 

Public Member Functions

 JKQTPSynchronized ()
 default constructor, the internal data is default-initialized
 
 JKQTPSynchronized (const JKQTPSynchronized< T > &other)
 locks other and copies its contents to this new class
 
 JKQTPSynchronized (const T &d)
 initializing constructor, the internal data is initialized with d
 
 JKQTPSynchronized (JKQTPSynchronized< T > &&other)
 locks other and moves its contents to this new class. The mutex in other is NOT moved!
 
 JKQTPSynchronized (T &&d)
 initializing constructor, the internal data is initialized with d
 
T & get ()
 returns the internal data as a mutable reference, not thread-safe.
 
const T & get () const
 returns the internal data as a mutable reference, not thread-safe.
 
get_safe () const
 returns the value in the internal data storage, thread-safe.
 
void lock () const
 locks the internal mutex for writing, until unlock() is called
 
void lockForRead () const
 locks the internal mutex for writing, until unlock() is called
 
void lockForWrite () const
 locks the internal mutex for writing, until unlock() is called
 
T * operator-> ()
 gives access to the internal data, not thread-safe.
 
const T * operator-> () const
 gives access to the internal data, not thread-safe.
 
void set (const T &d)
 assign a value to the internal data storage, not thread-safe.
 
void set (T &&d)
 assign a value to the internal data storage, not thread-safe.
 
void set_safe (const T &d)
 assign a value to the internal data storage, thread-safe.
 
void set_safe (T &&d)
 assign a value to the internal data storage, thread-safe.
 
void unlock () const
 unlocks the internal mutex from a previous lock(), lockForWrite() or lockForRead() call
 

Static Public Attributes

static constexpr AdoptLockType AdoptLock { }
 tag, which is used in ReadLocker and WriteLocker to adopt a pre-locked JKQTPSynchronized<T>
 

Private Attributes

m_data
 
MutexType m_mutex
 

Detailed Description

template<class T>
class JKQTPSynchronized< T >

template class that wraps any datatype and combines it with a mutex, exposes the lock()/unlock() interface, so access to the contained data can be synchronized

Member Typedef Documentation

◆ data_type

template<class T >
typedef T JKQTPSynchronized< T >::data_type

contained data type T

◆ Locker

template<class T >
typedef JKQTPSynchronized<T>::WriteLocker JKQTPSynchronized< T >::Locker

type of a lock_guard for a JKQTPSynchronized<T> for writing

◆ MutexType

template<class T >
typedef QReadWriteLock JKQTPSynchronized< T >::MutexType

Mutex used by this temmplate.

Constructor & Destructor Documentation

◆ JKQTPSynchronized() [1/5]

template<class T >
JKQTPSynchronized< T >::JKQTPSynchronized ( )
inline

default constructor, the internal data is default-initialized

◆ JKQTPSynchronized() [2/5]

template<class T >
JKQTPSynchronized< T >::JKQTPSynchronized ( const T &  d)
inline

initializing constructor, the internal data is initialized with d

◆ JKQTPSynchronized() [3/5]

template<class T >
JKQTPSynchronized< T >::JKQTPSynchronized ( T &&  d)
inline

initializing constructor, the internal data is initialized with d

◆ JKQTPSynchronized() [4/5]

template<class T >
JKQTPSynchronized< T >::JKQTPSynchronized ( const JKQTPSynchronized< T > &  other)
inline

locks other and copies its contents to this new class

◆ JKQTPSynchronized() [5/5]

template<class T >
JKQTPSynchronized< T >::JKQTPSynchronized ( JKQTPSynchronized< T > &&  other)
inline

locks other and moves its contents to this new class. The mutex in other is NOT moved!

Member Function Documentation

◆ get() [1/2]

template<class T >
T & JKQTPSynchronized< T >::get ( )
inline

returns the internal data as a mutable reference, not thread-safe.

Note
You need to lock this object before calling this function.

◆ get() [2/2]

template<class T >
const T & JKQTPSynchronized< T >::get ( ) const
inline

returns the internal data as a mutable reference, not thread-safe.

Note
You need to lock this object before calling this function.

◆ get_safe()

template<class T >
T JKQTPSynchronized< T >::get_safe ( ) const
inline

returns the value in the internal data storage, thread-safe.

◆ lock()

template<class T >
void JKQTPSynchronized< T >::lock ( ) const
inline

locks the internal mutex for writing, until unlock() is called

Note
Use WriteLocker or Locker instances to actually lock, using a RAII-idiom, as this is safer than doing this by hand!

◆ lockForRead()

template<class T >
void JKQTPSynchronized< T >::lockForRead ( ) const
inline

locks the internal mutex for writing, until unlock() is called

Note
Use WriteLocker or Locker instances to actually lock, using a RAII-idiom, as this is safer than doing this by hand!

◆ lockForWrite()

template<class T >
void JKQTPSynchronized< T >::lockForWrite ( ) const
inline

locks the internal mutex for writing, until unlock() is called

Note
Use WriteLocker or Locker instances to actually lock, using a RAII-idiom, as this is safer than doing this by hand!

◆ operator->() [1/2]

template<class T >
T * JKQTPSynchronized< T >::operator-> ( )
inline

gives access to the internal data, not thread-safe.

Note
You need to lock this object before calling this function.

◆ operator->() [2/2]

template<class T >
const T * JKQTPSynchronized< T >::operator-> ( ) const
inline

gives access to the internal data, not thread-safe.

Note
You need to lock this object before calling this function.

◆ set() [1/2]

template<class T >
void JKQTPSynchronized< T >::set ( const T &  d)
inline

assign a value to the internal data storage, not thread-safe.

Note
You need to lock this object before calling this function.

◆ set() [2/2]

template<class T >
void JKQTPSynchronized< T >::set ( T &&  d)
inline

assign a value to the internal data storage, not thread-safe.

Note
You need to lock this object before calling this function.

◆ set_safe() [1/2]

template<class T >
void JKQTPSynchronized< T >::set_safe ( const T &  d)
inline

assign a value to the internal data storage, thread-safe.

◆ set_safe() [2/2]

template<class T >
void JKQTPSynchronized< T >::set_safe ( T &&  d)
inline

assign a value to the internal data storage, thread-safe.

◆ unlock()

template<class T >
void JKQTPSynchronized< T >::unlock ( ) const
inline

unlocks the internal mutex from a previous lock(), lockForWrite() or lockForRead() call

Note
Use Locker instances to actually lock, using a RAII-idiom, as this is safer than doing this by hand!

Member Data Documentation

◆ AdoptLock

template<class T >
constexpr AdoptLockType JKQTPSynchronized< T >::AdoptLock { }
staticconstexpr

tag, which is used in ReadLocker and WriteLocker to adopt a pre-locked JKQTPSynchronized<T>

◆ m_data

template<class T >
T JKQTPSynchronized< T >::m_data
private

◆ m_mutex

template<class T >
MutexType JKQTPSynchronized< T >::m_mutex
mutableprivate

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