Page MenuHomePhabricator

DataStorageSynchronization.patch

Authored By
woerner
Aug 31 2009, 1:19 PM
Size
6 KB
Referenced Files
None
Subscribers
None

DataStorageSynchronization.patch

Index: mitkDataStorage.cpp
===================================================================
--- mitkDataStorage.cpp (revision 18719)
+++ mitkDataStorage.cpp (working copy)
@@ -22,6 +22,7 @@
#include "mitkNodePredicateBase.h"
#include "mitkNodePredicateProperty.h"
#include "mitkGroupTagProperty.h"
+#include "itkMutexLockHolder.h"
#include "itkCommand.h"
@@ -68,7 +69,9 @@
mitk::DataTreeNode* mitk::DataStorage::GetNamedNode(const char* name) const
-{
+
+{
+
if (name == NULL)
return NULL;
@@ -111,6 +114,7 @@
void mitk::DataStorage::PrintSelf(std::ostream& os, itk::Indent indent) const
{
+
//Superclass::PrintSelf(os, indent);
mitk::DataStorage::SetOfObjects::ConstPointer all = this->GetAll();
os << indent << "DataStorage " << this << " is managing " << all->Size() << " objects. List of objects:" << std::endl;
@@ -206,6 +210,7 @@
void mitk::DataStorage::AddListeners( const mitk::DataTreeNode* _Node )
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_MutexOne);
// node must not be 0 and must not be yet registered
if(_Node && m_NodeModifiedObserverTags.find(_Node) == m_NodeModifiedObserverTags.end())
{
@@ -227,6 +232,7 @@
void mitk::DataStorage::RemoveListeners( const mitk::DataTreeNode* _Node )
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_MutexOne) ;
// node must not be 0 and must be registered
if(_Node && m_NodeModifiedObserverTags.find(_Node) != m_NodeModifiedObserverTags.end())
{
Index: mitkDataStorage.h
===================================================================
--- mitkDataStorage.h (revision 18719)
+++ mitkDataStorage.h (working copy)
@@ -25,6 +25,7 @@
#include "itkVectorContainer.h"
#include "mitkDataTreeNode.h"
#include "mitkGeometry3D.h"
+#include "itkSimpleFastMutexLock.h"
#include <map>
namespace mitk {
@@ -192,6 +193,9 @@
//##
const DataTreeNode::GroupTagList GetGroupTags() const;
+ /*ITK Mutex */
+ mutable itk::SimpleFastMutexLock m_MutexOne;
+
/* Public Events */
typedef Message1<const mitk::DataTreeNode*> DataStorageEvent;
//##Documentation
@@ -201,6 +205,8 @@
//## After registering, myObject->MyMethod() will be called every time a new node has been added to the DataStorage.
//## Observers should unregister by calling myDataStorage->AddNodeEvent.RemoveListener(myObject, MyObject::MyMethod).
//## Note: AddEvents are _not_ emitted if a node is added to DataStorage by adding it to the the underlying DataTree!
+
+ // member variable is not needed to be looked in multi threaded scenarios since the DataStorageEvent is a typedef for // a message1 obejct which is thread safe
DataStorageEvent AddNodeEvent;
//##Documentation
@@ -210,6 +216,8 @@
//## After registering, myObject->MyMethod() will be called every time a new node has been added to the DataStorage.
//## Observers should unregister by calling myDataStorage->RemoveNodeEvent.RemoveListener(myObject, MyObject::MyMethod).
//## Note: RemoveEvents are also emitted if a node was removed from the DataStorage by deleting it from the underlying DataTree
+
+ // member variable is not needed to be looked in multi threaded scenarios since the DataStorageEvent is a typedef for // a message1 obejct which is thread safe
DataStorageEvent RemoveNodeEvent;
//##Documentation
@@ -220,6 +228,8 @@
//## Observers should unregister by calling myDataStorage->ChangedNodeEvent.RemoveListener(myObject, MyObject::MyMethod).
//## Internally the DataStorage listens to itk::ModifiedEvents on the nodes and forwards them
//## to the listeners of this event.
+
+ // member variable is not needed to be looked in multi threaded scenarios since the DataStorageEvent is a typedef for // a message1 obejct which is thread safe
DataStorageEvent ChangedNodeEvent;
//##Documentation
@@ -230,6 +240,8 @@
//## Observers should unregister by calling myDataStorage->DeleteNodeEvent.RemoveListener(myObject, MyObject::MyMethod).
//## Internally the DataStorage listens to itk::DeleteEvents on the nodes and forwards them
//## to the listeners of this event.
+
+ // member variable is not needed to be looked in multi threaded scenarios since the DataStorageEvent is a typedef for // a message1 obejct which is thread safe
DataStorageEvent DeleteNodeEvent;
//##Documentation
Index: mitkStandaloneDataStorage.cpp
===================================================================
--- mitkStandaloneDataStorage.cpp (revision 18719)
+++ mitkStandaloneDataStorage.cpp (working copy)
@@ -22,6 +22,8 @@
#include "mitkNodePredicateBase.h"
#include "mitkNodePredicateProperty.h"
#include "mitkGroupTagProperty.h"
+#include "itkSimpleFastMutexLock.h"
+#include "itkMutexLockHolder.h"
mitk::StandaloneDataStorage::StandaloneDataStorage()
@@ -50,6 +52,7 @@
void mitk::StandaloneDataStorage::Add(mitk::DataTreeNode* node, const mitk::DataStorage::SetOfObjects* parents)
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_Mutex);
if (!IsInitialized())
throw 1; // insert exception handling here
/* check if node is in its own list of sources */
@@ -94,6 +97,7 @@
void mitk::StandaloneDataStorage::Remove(const mitk::DataTreeNode* node)
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_Mutex);
if (!IsInitialized())
throw 1; // insert exception handling here
if (node == NULL)
@@ -112,6 +116,7 @@
bool mitk::StandaloneDataStorage::Exists(const mitk::DataTreeNode* node) const
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_Mutex);
return (m_SourceNodes.find(node) != m_SourceNodes.end());
}
@@ -135,6 +140,7 @@
mitk::DataStorage::SetOfObjects::ConstPointer mitk::StandaloneDataStorage::GetAll() const
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock > locked(m_Mutex);
if (!IsInitialized())
throw 1; // insert exception handling here
@@ -214,12 +220,14 @@
mitk::DataStorage::SetOfObjects::ConstPointer mitk::StandaloneDataStorage::GetSources(const mitk::DataTreeNode* node, const NodePredicateBase* condition, bool onlyDirectSources) const
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock> locked(m_Mutex);
return this->GetRelations(node, m_SourceNodes, condition, onlyDirectSources);
}
mitk::DataStorage::SetOfObjects::ConstPointer mitk::StandaloneDataStorage::GetDerivations(const mitk::DataTreeNode* node, const NodePredicateBase* condition, bool onlyDirectDerivations) const
{
+ itk::MutexLockHolder<itk::SimpleFastMutexLock>locked(m_Mutex);
return this->GetRelations(node, m_DerivedNodes, condition, onlyDirectDerivations);
}
Index: mitkStandaloneDataStorage.h
===================================================================
--- mitkStandaloneDataStorage.h (revision 18719)
+++ mitkStandaloneDataStorage.h (working copy)
@@ -89,6 +89,9 @@
//##
SetOfObjects::ConstPointer GetAll() const;
+ /*ITK Mutex */
+ mutable itk::SimpleFastMutexLock m_Mutex;
+
protected:
//##Documentation

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
269
Default Alt Text
DataStorageSynchronization.patch (6 KB)

Event Timeline

Patch to test the DataStorageSynchronization on Linux systems