Allow content parts to not be preset in XML.
[dcpomatic.git] / src / lib / signaller.h
index 4ef9b38b36f99a304e4cbbbdf3d6204ee02102b4..c6037deaa085c737bce9e750b2171fba67aecd53 100644 (file)
@@ -22,7 +22,6 @@
 
 #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 ();
                }
@@ -103,8 +112,8 @@ public:
                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;
 };