summaryrefslogtreecommitdiff
path: root/src/lib/encoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-06-07 16:05:43 +0100
committerCarl Hetherington <cth@carlh.net>2016-06-07 16:05:43 +0100
commit538af3d961b5017303cedb56fa35c9be23d1658a (patch)
tree5e1edb101585afa4e6bba75a9e2b7b49ffc00406 /src/lib/encoder.cc
parent2860640c7cf39410bfb21f69ce05e345e9078fa3 (diff)
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.
Diffstat (limited to 'src/lib/encoder.cc')
-rw-r--r--src/lib/encoder.cc30
1 files changed, 4 insertions, 26 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<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 ());