From b34310b4e90af1442363fe09db082d68e1721130 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 20 Jul 2016 10:21:13 +0100 Subject: [PATCH] Try to fix intermittent deadlocks with encoding servers. 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 | 4 ++++ src/lib/encoder.cc | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c4f19db9..062677604 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-07-20 Carl Hetherington + + * Try to fix intermittent hangs with encoding servers. + 2016-07-14 Carl Hetherington * Version 2.9.3 released. diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index cc2deaa93..652412ddf 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -207,11 +207,13 @@ Encoder::encode (shared_ptr 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 (); -- 2.30.2