summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/broker/ConnectionObservers.h
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src/qpid/broker/ConnectionObservers.h')
-rw-r--r--qpid/cpp/src/qpid/broker/ConnectionObservers.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/broker/ConnectionObservers.h b/qpid/cpp/src/qpid/broker/ConnectionObservers.h
index b36097cdbb..07e515f3c9 100644
--- a/qpid/cpp/src/qpid/broker/ConnectionObservers.h
+++ b/qpid/cpp/src/qpid/broker/ConnectionObservers.h
@@ -23,6 +23,9 @@
*/
#include "ConnectionObserver.h"
+#include "qpid/sys/Mutex.h"
+#include <set>
+#include <algorithm>
namespace qpid {
namespace broker {
@@ -30,12 +33,18 @@ namespace broker {
/**
* A collection of connection observers.
* Calling a ConnectionObserver function will call that function on each observer.
+ * THREAD SAFE.
*/
class ConnectionObservers : public ConnectionObserver {
public:
- // functions for managing the collection of observers
void add(boost::shared_ptr<ConnectionObserver> observer) {
- observers.push_back(observer);
+ sys::Mutex::ScopedLock l(lock);
+ observers.insert(observer);
+ }
+
+ void remove(boost::shared_ptr<ConnectionObserver> observer) {
+ sys::Mutex::ScopedLock l(lock);
+ observers.erase(observer);
}
void connection(Connection& c) {
@@ -55,10 +64,12 @@ class ConnectionObservers : public ConnectionObserver {
}
private:
- typedef std::vector<boost::shared_ptr<ConnectionObserver> > Observers;
+ typedef std::set<boost::shared_ptr<ConnectionObserver> > Observers;
+ sys::Mutex lock;
Observers observers;
template <class F> void each(F f) {
+ sys::Mutex::ScopedLock l(lock);
std::for_each(observers.begin(), observers.end(), f);
}
};