summaryrefslogtreecommitdiff
path: root/src/lib/encoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-06-26 11:04:02 +0100
committerCarl Hetherington <cth@carlh.net>2014-06-26 11:04:02 +0100
commit02f028d271677b3b3669b5cdfda1597108a34b80 (patch)
tree76618364e855af0e31bc88c44f8357da62d8c5f5 /src/lib/encoder.cc
parentee8f7f7edb1da818f60dfd2da11ca458aad0dc35 (diff)
Use full/empty conditions rather than just a single condition for the server and encoder.
Diffstat (limited to 'src/lib/encoder.cc')
-rw-r--r--src/lib/encoder.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index e83ac70f5..02a271029 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -108,8 +108,8 @@ Encoder::process_end ()
/* Keep waking workers until the queue is empty */
while (!_queue.empty ()) {
- _condition.notify_all ();
- _condition.wait (lock);
+ _empty_condition.notify_all ();
+ _full_condition.wait (lock);
}
lock.unlock ();
@@ -194,7 +194,7 @@ Encoder::process_video (shared_ptr<PlayerVideoFrame> pvf, bool same)
/* Wait until the queue has gone down a bit */
while (_queue.size() >= _threads.size() * 2 && !_terminate) {
LOG_TIMING ("decoder sleeps with queue of %1", _queue.size());
- _condition.wait (lock);
+ _full_condition.wait (lock);
LOG_TIMING ("decoder wakes with queue of %1", _queue.size());
}
@@ -226,8 +226,11 @@ Encoder::process_video (shared_ptr<PlayerVideoFrame> pvf, bool same)
_film->j2k_bandwidth(), _film->resolution(), _film->log()
)
));
-
- _condition.notify_all ();
+
+ /* The queue might not be empty any more, so notify anything which is
+ waiting on that.
+ */
+ _empty_condition.notify_all ();
_have_a_real_frame[pvf->eyes()] = true;
}
@@ -248,7 +251,8 @@ Encoder::terminate_threads ()
{
boost::mutex::scoped_lock lock (_mutex);
_terminate = true;
- _condition.notify_all ();
+ _full_condition.notify_all ();
+ _empty_condition.notify_all ();
}
for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
@@ -271,12 +275,12 @@ try
*/
int remote_backoff = 0;
- while (1) {
+ while (true) {
LOG_TIMING ("[%1] encoder thread sleeps", boost::this_thread::get_id());
boost::mutex::scoped_lock lock (_mutex);
while (_queue.empty () && !_terminate) {
- _condition.wait (lock);
+ _empty_condition.wait (lock);
}
if (_terminate) {
@@ -338,8 +342,9 @@ try
dcpomatic_sleep (remote_backoff);
}
+ /* The queue might not be full any more, so notify anything that is waiting on that */
lock.lock ();
- _condition.notify_all ();
+ _full_condition.notify_all ();
}
}
catch (...)