Allow content parts to not be preset in XML.
[dcpomatic.git] / src / lib / signaller.h
index 408cfcf5b41f9613213535fcda4a949ef86bf6e4..c6037deaa085c737bce9e750b2171fba67aecd53 100644 (file)
@@ -20,9 +20,8 @@
 #ifndef DCPOMATIC_SIGNALLER_H
 #define DCPOMATIC_SIGNALLER_H
 
-#include "ui_signaller.h"
+#include "signal_manager.h"
 #include <boost/thread/mutex.hpp>
-#include <boost/signals2.hpp>
 
 class WrapperBase
 {
@@ -42,7 +41,17 @@ public:
        }
 
        bool finished () const {
-               boost::mutex::scoped_lock lm (_mutex);
+               boost::mutex::scoped_lock lm (_mutex, boost::try_to_lock);
+               if (!lm) {
+                       /* It's possible that emission of this
+                          wrapper's signal causes another signal to
+                          be emitted, which causes finished() on this
+                          wrapper to be called (by Signaller::emit).
+                          In this case, just say that the wrapper is
+                          not yet finished.
+                       */
+                       return false;
+               }
                return _finished;
        }
 
@@ -89,7 +98,7 @@ class Signaller
 public:
        /* Can be called from any thread */
        virtual ~Signaller () {
-               boost::mutex::scoped_lock lm (_mutex);
+               boost::mutex::scoped_lock lm (_signaller_mutex);
                for (std::list<WrapperBase*>::iterator i = _wrappers.begin(); i != _wrappers.end(); ++i) {
                        (*i)->invalidate ();
                }
@@ -100,11 +109,11 @@ public:
        void emit (T signal)
        {
                Wrapper<T>* w = new Wrapper<T> (signal);
-               if (ui_signaller) {
-                       ui_signaller->emit (boost::bind (&Wrapper<T>::signal, w));
+               if (signal_manager) {
+                       signal_manager->emit (boost::bind (&Wrapper<T>::signal, w));
                }
-               
-               boost::mutex::scoped_lock lm (_mutex);
+
+               boost::mutex::scoped_lock lm (_signaller_mutex);
 
                /* Clean up finished Wrappers */
                std::list<WrapperBase*>::iterator i = _wrappers.begin ();
@@ -124,7 +133,7 @@ public:
 
 private:
        /* Protect _wrappers */
-       boost::mutex _mutex;
+       boost::mutex _signaller_mutex;
        std::list<WrapperBase*> _wrappers;
 };