From 538af3d961b5017303cedb56fa35c9be23d1658a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 7 Jun 2016 16:05:43 +0100 Subject: [PATCH] Remove some flawed condition manipulation. 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 | 30 ++++-------------------------- src/lib/encoder.h | 5 +---- src/wx/job_view.cc | 2 +- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 36e4fe55d..f766cccd9 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -59,8 +59,6 @@ int const Encoder::_history_size = 25; Encoder::Encoder (shared_ptr film, shared_ptr writer) : _film (film) , _position (0) - , _terminate_enqueue (false) - , _terminate_encoding (false) , _writer (writer) { servers_list_changed (); @@ -69,11 +67,6 @@ Encoder::Encoder (shared_ptr film, shared_ptr 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 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 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::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 vf = _queue.front (); LOG_TIMING ("encoder-pop thread=%1 frame=%2 eyes=%3", boost::this_thread::get_id(), vf->index(), vf->eyes ()); diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 7e6fc4f30..6b830abba 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -55,7 +55,7 @@ class Encoder : public boost::noncopyable, public ExceptionStore { public: Encoder (boost::shared_ptr, boost::shared_ptr); - 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 _threads; diff --git a/src/wx/job_view.cc b/src/wx/job_view.cc index 8718d14e3..767c7ca5a 100644 --- a/src/wx/job_view.cc +++ b/src/wx/job_view.cc @@ -39,7 +39,7 @@ JobView::JobView (shared_ptr 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; -- 2.30.2