#include "signal_manager.h"
#include <boost/thread/mutex.hpp>
-#include <boost/signals2.hpp>
class WrapperBase
{
}
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;
}
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 ();
}
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 ();
private:
/* Protect _wrappers */
- boost::mutex _mutex;
+ boost::mutex _signaller_mutex;
std::list<WrapperBase*> _wrappers;
};