OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Attributes | List of all members
WSharedObject< T > Class Template Reference

Wrapper around an object/type for thread safe sharing of objects among multiple threads. More...

#include <WSharedObject.h>

+ Inheritance diagram for WSharedObject< T >:
+ Collaboration diagram for WSharedObject< T >:

Public Types

typedef T ValueT
 The type protected by this shared object class. More...
 
typedef std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
 Type for read tickets. More...
 
typedef std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
 Type for write tickets. More...
 
typedef std::shared_ptr< WSharedObject< T > > SPtr
 Shared pointer abbreviation. More...
 
typedef std::shared_ptr< WSharedObject< T > > ConstSPtr
 Const shared ptr abbreviation. More...
 

Public Member Functions

 WSharedObject ()
 Default constructor. More...
 
virtual ~WSharedObject ()
 Destructor. More...
 
ReadTicket getReadTicket () const
 Returns a ticket to get read access to the contained data. More...
 
WriteTicket getWriteTicket (bool suppressNotify=false) const
 Returns a ticket to get write access to the contained data. More...
 
std::shared_ptr< WConditiongetChangeCondition () const
 This condition fires whenever the encapsulated object changed. More...
 

Protected Attributes

m_object
 The object wrapped by this class. More...
 
std::shared_ptr< std::shared_mutex > m_lock
 The lock to ensure thread safe access. More...
 
std::shared_ptr< WConditionm_changeCondition
 This condition set fires whenever the contained object changes. More...
 

Detailed Description

template<typename T>
class WSharedObject< T >

Wrapper around an object/type for thread safe sharing of objects among multiple threads.

The advantage of this class over WFlag is, that WFlag just protects simple get/set operations, while this class can protect a whole bunch of operations on the encapsulated object.

Definition at line 44 of file WSharedObject.h.

Member Typedef Documentation

◆ ConstSPtr

template<typename T >
typedef std::shared_ptr< WSharedObject< T > > WSharedObject< T >::ConstSPtr

Const shared ptr abbreviation.

Definition at line 80 of file WSharedObject.h.

◆ ReadTicket

template<typename T >
typedef std::shared_ptr< WSharedObjectTicketRead< T > > WSharedObject< T >::ReadTicket

Type for read tickets.

Definition at line 65 of file WSharedObject.h.

◆ SPtr

template<typename T >
typedef std::shared_ptr< WSharedObject< T > > WSharedObject< T >::SPtr

Shared pointer abbreviation.

Definition at line 75 of file WSharedObject.h.

◆ ValueT

template<typename T >
typedef T WSharedObject< T >::ValueT

The type protected by this shared object class.

Definition at line 60 of file WSharedObject.h.

◆ WriteTicket

template<typename T >
typedef std::shared_ptr< WSharedObjectTicketWrite< T > > WSharedObject< T >::WriteTicket

Type for write tickets.

Definition at line 70 of file WSharedObject.h.

Constructor & Destructor Documentation

◆ WSharedObject()

template<typename T >
WSharedObject< T >::WSharedObject

Default constructor.

Definition at line 127 of file WSharedObject.h.

◆ ~WSharedObject()

template<typename T >
WSharedObject< T >::~WSharedObject
virtual

Destructor.

Definition at line 135 of file WSharedObject.h.

Member Function Documentation

◆ getChangeCondition()

template<typename T >
std::shared_ptr< WCondition > WSharedObject< T >::getChangeCondition

This condition fires whenever the encapsulated object changed.

This is fired automatically by endWrite().

Returns
the condition

Definition at line 141 of file WSharedObject.h.

Referenced by WGEColormapping::getChangeCondition(), WGEScreenCapture::getRecordCondition(), WGEColormapping::WGEColormapping(), and WPropertyGroupBase::WPropertyGroupBase().

+ Here is the caller graph for this function:

◆ getReadTicket()

template<typename T >
WSharedObject< T >::ReadTicket WSharedObject< T >::getReadTicket

Returns a ticket to get read access to the contained data.

After the ticket is freed, the read lock vanishes.

Returns
the read ticket

Definition at line 147 of file WSharedObject.h.

Referenced by WQtNetworkSceneLayout::addItem(), WLogger::addLogMessage(), WSharedSequenceContainer< S >::at(), WGEGridNode::callback(), WGEColormapping::callback(), WMainWindow::closeStage1Thread(), WSharedAssociativeContainer< T >::count(), WSharedSequenceContainer< S >::count(), WModuleFactory::create(), WSharedAssociativeContainer< T >::empty(), WSharedSequenceContainer< S >::find(), WModuleFactory::findByUUID(), WPropertyGroupBase::findProperty(), WModuleFactory::getAllPrototypes(), WPropertyList< T >::getAsString(), WPropertyStruct< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::getAsString(), WModuleFactory::getCompatiblePrototypes(), WBatchLoader::getDataModuleList(), WModuleContainer::getDataModules(), WSubject::getDatasets(), WGEGridNode::getGrid(), WModuleContainer::getModules(), WModuleContainer::getPossibleConnections(), WPropertyGroupBase::getProperties(), WPropertyStruct< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::getProperty(), WModuleFactory::getPrototypes(), WModuleFactory::getPrototypesByType(), WGEColormapping::getReadTicket(), WPropertyGroupBase::getReadTicket(), WGEScreenCapture::getRecordingInformation(), WThreadedFunctionTest::FuncType::getResult(), WWorkerThreadTest::FuncType::getResult(), WItemSelection::getSelector(), WItemSelection::getSelectorAll(), WItemSelection::getSelectorFirst(), WItemSelection::getSelectorLast(), WItemSelection::getSelectorNone(), WDataHandler::getSubjectByID(), WDataHandler::getSubjects(), WModuleFactory::isPrototypeAvailable(), WGEScreenCapture::isRecording(), WSharedAssociativeContainer< T >::max_size(), WSharedSequenceContainer< S >::operator[](), WGEShader::processShader(), WGEColormapping::resetSortIndices(), WPropertyStruct< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::set(), WPropertyStruct< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 >::setAsString(), WGEShader::setDefine(), WGEColormapping::setSortIndices(), WSharedAssociativeContainer< T >::size(), WSharedSequenceContainer< S >::size(), WThreadedFunctionBase::status(), WModuleContainer::stop(), WThreadedFunctionTest::FuncType::stopped(), WWorkerThreadTest::FuncType::stopped(), WThreadedTrackingFunctionTest::testCompute(), WThreadedFunctionTest::testExceptionHandling(), WGEColormapping::updateBounds(), WProjectFile::WProjectFile(), and WPropertyGroupBase::WPropertyGroupBase().

+ Here is the caller graph for this function:

◆ getWriteTicket()

template<typename T >
WSharedObject< T >::WriteTicket WSharedObject< T >::getWriteTicket ( bool  suppressNotify = false) const

Returns a ticket to get write access to the contained data.

After the ticket is freed, the write lock vanishes.

Parameters
suppressNotifytrue if no notification should be send after unlocking.
Returns
the ticket

Definition at line 155 of file WSharedObject.h.

Referenced by WModuleContainer::add(), WPropertyGroupBase::addArbitraryProperty(), WGEShader::addPreprocessor(), WPropertyObserver::cancelSubscriptions(), WPropertyGroup::clear(), WSharedAssociativeContainer< T >::clear(), WSharedSequenceContainer< S >::clear(), WDataHandler::clear(), WSubject::clear(), WGEPostprocessingNode::clear(), WGEShader::clearPreprocessors(), WUIWidgetBase::closeChildren(), WSharedAssociativeContainer< T >::erase(), WSharedSequenceContainer< S >::erase(), WThreadedFunctionTest::FuncType::FuncType(), WWorkerThreadTest::FuncType::FuncType(), WSubject::getDatasetsForWriting(), WPropertyObserver::handled(), WThreadedFunctionTest::handleException(), WThreadedFunction< Function_T >::handleThreadDone(), WThreadedFunction< Function_T >::handleThreadException(), WSharedAssociativeContainer< T >::insert(), WGEPostprocessingNode::insert(), WModuleFactory::load(), WGEColormapping::moveDown(), WGEColormapping::moveTo(), WGEColormapping::moveToBottom(), WGEColormapping::moveToTop(), WGEColormapping::moveUp(), WPropertyObserver::observe(), WThreadedFunctionTest::FuncType::operator()(), WWorkerThreadTest::FuncType::operator()(), WThreadedTrackingFunctionTest::pntVis(), WSharedSequenceContainer< S >::pop_back(), WPropertyObserver::propertyUpdated(), WSharedSequenceContainer< S >::push_back(), WSharedSequenceContainer< S >::push_front(), WGEScreenCapture::record(), WProjectFile::registerParser(), WSharedSequenceContainer< S >::remove(), WGEPostprocessingNode::remove(), WModuleContainer::remove(), WSubject::removeDataSet(), WGEShader::removePreprocessor(), WPropertyGroup::removeProperty(), WDataHandler::removeSubject(), WSharedSequenceContainer< S >::replace(), WThreadedFunctionTest::FuncType::reset(), WWorkerThreadTest::FuncType::reset(), WGEScreenCapture::resetFrameCounter(), WGEGridNode::setGrid(), WQtNetworkSceneLayout::setModuleDefaultFlags(), WQtNetworkSceneLayout::setModuleDefaultPosition(), WSharedSequenceContainer< S >::sort(), WSharedSequenceContainer< S >::stableSort(), WModuleContainer::stop(), WThreadedTrackingFunctionTest::testCompute(), WThreadedFunctionTest::testExceptionHandling(), WGEColormapping::textureUpdate(), WSharedSequenceContainer< S >::unique_push_back(), WSharedSequenceContainer< S >::unique_push_front(), WPropertyObserver::updateSubscriptions(), WGEGridNode::WGEGridNode(), WGEScreenCapture::WGEScreenCapture(), WThreadedFunction< Function_T >::WThreadedFunction(), and WThreadedFunctionBase::WThreadedFunctionBase().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_changeCondition

template<typename T >
std::shared_ptr< WCondition > WSharedObject< T >::m_changeCondition
protected

This condition set fires whenever the contained object changes.

This corresponds to the Observable pattern.

Definition at line 121 of file WSharedObject.h.

◆ m_lock

template<typename T >
std::shared_ptr< std::shared_mutex > WSharedObject< T >::m_lock
mutableprotected

The lock to ensure thread safe access.

This member is mutable as the getReadTicket and getWriteTicket functions are const but need a non-const reference to m_lock.

Definition at line 116 of file WSharedObject.h.

◆ m_object

template<typename T >
T WSharedObject< T >::m_object
mutableprotected

The object wrapped by this class.

This member is mutable as the getReadTicket and getWriteTicket functions are const but need a non-const reference to m_object.

Definition at line 110 of file WSharedObject.h.


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