Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 62fd0fac authored by schultezub's avatar schultezub
Browse files

added mutexes to observer implementation

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@191 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent b7e1f9b7
......@@ -19,14 +19,17 @@ namespace TUMVis {
}
void Observable::addObserver(Observer* o) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
_observers.insert(o);
}
void Observable::removeObserver(Observer* o) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
_observers.erase(o);
}
void Observable::notifyObservers() const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
for (std::set<Observer*>::iterator it = _observers.begin(); it != _observers.end(); ++it) {
(*it)->onNotify();
}
......
#ifndef OBSERVER_H__
#define OBSERVER_H__
#include "tbb/include/tbb/spin_mutex.h"
#include <set>
namespace TUMVis {
......@@ -53,6 +54,7 @@ namespace TUMVis {
void notifyObservers() const;
mutable std::set<Observer*> _observers; ///< Set of all observers for this subject
mutable tbb::spin_mutex _localMutex;
};
// - Generic variant ------------------------------------------------------------------------------
......@@ -93,6 +95,7 @@ namespace TUMVis {
* \param o GenericObserver<T> to add
*/
void addObserver(GenericObserver<T>* o) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
_observers.insert(o);
};
......@@ -102,6 +105,7 @@ namespace TUMVis {
* \param o GenericObserver<T> to remove
*/
void removeObserver(GenericObserver<T>* o) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
_observers.erase(o);
};
......@@ -112,12 +116,14 @@ namespace TUMVis {
* \param args Argument struct to be passed to observer.
*/
void notifyObservers(const T& args) const {
tbb::spin_mutex::scoped_lock lock(_localMutex);
for (std::set< GenericObserver<T>* >::iterator it = _observers.begin(); it != _observers.end(); ++it) {
(*it)->onNotify(args);
}
};
mutable std::set< GenericObserver<T>* > _observers; ///< Set of all observers for this subject
mutable tbb::spin_mutex _localMutex;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment