Remove some flawed condition manipulation.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2016 15:05:43 +0000 (16:05 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Jun 2016 15:05:43 +0000 (16:05 +0100)
I think this stuff is unnecessary as wait() is interruptible
by boost::thread::interrupt.  Hence instead of setting a flag
then signalling the condition we can just do interrupt(), the
exception will be thrown and that's that.

src/lib/encoder.cc
src/lib/encoder.h
src/wx/job_view.cc

index 36e4fe55d4adba72ca2aff7416393c6a5e7bf85c..f766cccd90aad51e4395c04aa50cc1dc23566520 100644 (file)
@@ -59,8 +59,6 @@ int const Encoder::_history_size = 25;
 Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
        : _film (film)
        , _position (0)
-       , _terminate_enqueue (false)
-       , _terminate_encoding (false)
        , _writer (writer)
 {
        servers_list_changed ();
@@ -69,11 +67,6 @@ Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
 Encoder::~Encoder ()
 {
        terminate_threads ();
-
-       boost::mutex::scoped_lock lm (_queue_mutex);
-       _terminate_enqueue = true;
-       _full_condition.notify_all ();
-       _empty_condition.notify_all ();
 }
 
 void
@@ -201,16 +194,12 @@ Encoder::enqueue (shared_ptr<PlayerVideo> pv)
        /* XXX: discard 3D here if required */
 
        /* Wait until the queue has gone down a bit */
-       while (_queue.size() >= threads * 2 && !_terminate_enqueue) {
+       while (_queue.size() >= threads * 2) {
                LOG_TIMING ("decoder-sleep queue=%1", _queue.size());
                _full_condition.wait (queue_lock);
                LOG_TIMING ("decoder-wake queue=%1", _queue.size());
        }
 
-       if (_terminate_enqueue) {
-               return;
-       }
-
        _writer->rethrow ();
        /* Re-throw any exception raised by one of our threads.  If more
           than one has thrown an exception, only one will be rethrown, I think;
@@ -253,27 +242,20 @@ Encoder::enqueue (shared_ptr<PlayerVideo> pv)
 void
 Encoder::terminate_threads ()
 {
-       {
-               boost::mutex::scoped_lock queue_lock (_queue_mutex);
-               _terminate_encoding = true;
-       }
-
        boost::mutex::scoped_lock threads_lock (_threads_mutex);
 
        int n = 0;
        for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
                LOG_GENERAL ("Terminating thread %1 of %2", n + 1, _threads.size ());
                (*i)->interrupt ();
-               if ((*i)->joinable ()) {
-                       (*i)->join ();
-               }
+               DCPOMATIC_ASSERT ((*i)->joinable ());
+               (*i)->join ();
                delete *i;
                LOG_GENERAL_NC ("Thread terminated");
                ++n;
        }
 
        _threads.clear ();
-       _terminate_encoding = false;
 }
 
 void
@@ -296,14 +278,10 @@ try
 
                LOG_TIMING ("encoder-sleep thread=%1", boost::this_thread::get_id());
                boost::mutex::scoped_lock lock (_queue_mutex);
-               while (_queue.empty () && !_terminate_encoding) {
+               while (_queue.empty ()) {
                        _empty_condition.wait (lock);
                }
 
-               if (_terminate_encoding) {
-                       return;
-               }
-
                LOG_TIMING ("encoder-wake thread=%1 queue=%2", boost::this_thread::get_id(), _queue.size());
                shared_ptr<DCPVideo> vf = _queue.front ();
                LOG_TIMING ("encoder-pop thread=%1 frame=%2 eyes=%3", boost::this_thread::get_id(), vf->index(), vf->eyes ());
index 7e6fc4f308c226b767f3dcac42154d7b415a0d00..6b830abba15f6585e28fc101137861cbdcae4ea7 100644 (file)
@@ -55,7 +55,7 @@ class Encoder : public boost::noncopyable, public ExceptionStore
 {
 public:
        Encoder (boost::shared_ptr<const Film>, boost::shared_ptr<Writer>);
-       virtual ~Encoder ();
+       ~Encoder ();
 
        /** Called to indicate that a processing run is about to begin */
        void begin ();
@@ -94,9 +94,6 @@ private:
        /** Current DCP frame index */
        Frame _position;
 
-       /* XXX: probably should be atomic */
-       bool _terminate_enqueue;
-       bool _terminate_encoding;
        /** Mutex for _threads */
        mutable boost::mutex _threads_mutex;
        std::list<boost::thread *> _threads;
index 8718d14e336888fa418e2289b022ef5623a51322..767c7ca5a1993ace67f1fb31a341e80a29d9de47 100644 (file)
@@ -39,7 +39,7 @@ JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wx
        /* This seems to be required to allow the gauge to shrink under OS X */
        _gauge->SetMinSize (wxSize (0, -1));
        _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
-       _message = new wxStaticText (container, wxID_ANY, wxT (" \n "));
+       _message = new wxStaticText (container, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
        _gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
        table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
        ++n;