Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /mt/SignalProxy.h [0a3dc1] .. [0a1223] Maximize Restore

  Switch to side-by-side view

--- a/mt/SignalProxy.h
+++ b/mt/SignalProxy.h
@@ -19,16 +19,18 @@
 #define _SIGNAL_PROXY_H_
 
 #include <qqueue.h>
-#include "libgui/AsyncSync.h"
+#include "mt/AsyncSync.h"
+#include "mt/Mutex.h"
+#include "mt/MutexGuard.h"
 
 //***************************************************************************
-
 template <class T> class SignalProxy: protected AsyncSync
 {
 public:
     SignalProxy(QObject *owner, const char *slot);
 };
 
+//***************************************************************************
 template <class T> SignalProxy<T>::SignalProxy(QObject *owner, const char *slot)
     :AsyncSync(owner)
 {
@@ -36,7 +38,7 @@
 }
 
 //***************************************************************************
-
+//***************************************************************************
 template <class T> class SignalProxy1: protected AsyncSync
 {
 public:
@@ -46,36 +48,48 @@
     virtual T *dequeue();
     virtual unsigned int count();
 private:
-    QQueue<T> queue;
+    QQueue<T> m_queue;
+    Mutex m_lock;
 };
 
+//***************************************************************************
 template <class T> SignalProxy1<T>::SignalProxy1(QObject *owner, const char *slot)
 {
-    queue.setAutoDelete(false);
+    m_queue.setAutoDelete(false);
     QObject::connect(this, SIGNAL(Activated()), owner, slot);
 }
 
+//***************************************************************************
 template <class T> SignalProxy1<T>::~SignalProxy1()
 {
-    queue.setAutoDelete(true);
-    queue.clear();
+    MutexGuard lock(m_lock);
+
+    m_queue.setAutoDelete(true);
+    m_queue.clear();
 }
 
+//***************************************************************************
 template <class T> void SignalProxy1<T>::enqueue(const T &param)
 {
+    MutexGuard lock(m_lock);
+
     T *copy = new T(param);
-    queue.enqueue(copy);
+    m_queue.enqueue(copy);
     AsyncHandler();
 }
 
+//***************************************************************************
 template <class T> T *SignalProxy1<T>::dequeue()
 {
-    return queue.dequeue();
+    MutexGuard lock(m_lock);
+    return m_queue.dequeue();
 }
 
+//***************************************************************************
 template <class T> unsigned int SignalProxy1<T>::count()
 {
-    return queue.count();
+    MutexGuard lock(m_lock);
+    return m_queue.count();
 }
 
 #endif //  _SIGNAL_PROXY_H_