X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsignaller.h;h=a6c74c954feb7eea674e51f608d8235c5feccb34;hb=e3bb6707618b6a313a490f387bffbf0b6a064643;hp=408cfcf5b41f9613213535fcda4a949ef86bf6e4;hpb=05c37bfdb86be26497d5baa448a0cbda20e33bed;p=dcpomatic.git diff --git a/src/lib/signaller.h b/src/lib/signaller.h index 408cfcf5b..a6c74c954 100644 --- a/src/lib/signaller.h +++ b/src/lib/signaller.h @@ -1,28 +1,28 @@ /* Copyright (C) 2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ #ifndef DCPOMATIC_SIGNALLER_H #define DCPOMATIC_SIGNALLER_H -#include "ui_signaller.h" +#include "signal_manager.h" #include -#include class WrapperBase { @@ -42,7 +42,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 +99,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::iterator i = _wrappers.begin(); i != _wrappers.end(); ++i) { (*i)->invalidate (); } @@ -100,11 +110,11 @@ public: void emit (T signal) { Wrapper* w = new Wrapper (signal); - if (ui_signaller) { - ui_signaller->emit (boost::bind (&Wrapper::signal, w)); + if (signal_manager) { + signal_manager->emit (boost::bind (&Wrapper::signal, w)); } - - boost::mutex::scoped_lock lm (_mutex); + + boost::mutex::scoped_lock lm (_signaller_mutex); /* Clean up finished Wrappers */ std::list::iterator i = _wrappers.begin (); @@ -124,7 +134,7 @@ public: private: /* Protect _wrappers */ - boost::mutex _mutex; + boost::mutex _signaller_mutex; std::list _wrappers; };