Try to fix intermittent deadlocks with encoding servers.
authorCarl Hetherington <cth@carlh.net>
Wed, 20 Jul 2016 09:21:13 +0000 (10:21 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 Jul 2016 09:21:13 +0000 (10:21 +0100)
Before this commit all encoding threads could be removed and then
::encode would always wait on _full_condition no matter what the
queue size.

ChangeLog
src/lib/encoder.cc

index 4c4f19db9824fad9511d0359cbb555b1e2d9462a..062677604504fd239fbb2b216cdf0420ad66bb65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-07-20  Carl Hetherington  <cth@carlh.net>
+
+       * Try to fix intermittent hangs with encoding servers.
+
 2016-07-14  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.9.3 released.
index cc2deaa9387333b2efbc9a3ed965611fb998c416..652412ddf01d455941c8760db1b080cf2cef68eb 100644 (file)
@@ -207,11 +207,13 @@ Encoder::encode (shared_ptr<PlayerVideo> pv)
 
        boost::mutex::scoped_lock queue_lock (_queue_mutex);
 
-       /* Wait until the queue has gone down a bit */
-       while (_queue.size() >= threads * 2) {
-               LOG_TIMING ("decoder-sleep queue=%1", _queue.size());
+       /* Wait until the queue has gone down a bit.  Allow one thing in the queue even
+          when there are no threads.
+       */
+       while (_queue.size() >= (threads * 2) + 1) {
+               LOG_TIMING ("decoder-sleep queue=%1 threads=%2", _queue.size(), threads);
                _full_condition.wait (queue_lock);
-               LOG_TIMING ("decoder-wake queue=%1", _queue.size());
+               LOG_TIMING ("decoder-wake queue=%1 threads=%2", _queue.size(), threads);
        }
 
        _writer->rethrow ();