From 01c3453026ecc303cc2ee49516650db95bf88ca8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 19 Aug 2015 19:24:03 +0100 Subject: [PATCH] Fix loss of host's encoding threads when servers list changes. --- src/lib/encoder.cc | 45 +++++++++++++++++++++------------------------ src/lib/encoder.h | 1 - 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 08f4e66d4..195b10f44 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -71,32 +71,9 @@ Encoder::~Encoder () terminate_threads (); } -/** Add a worker thread for a each thread on a remote server. Caller must hold - * a lock on _mutex, or know that one is not currently required to - * safely modify _threads. - */ -void -Encoder::add_worker_threads (ServerDescription d) -{ - LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), d.threads(), d.host_name ()); - for (int i = 0; i < d.threads(); ++i) { - _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, d))); - } - - _writer->set_encoder_threads (_threads.size ()); -} - void Encoder::begin () { - if (!Config::instance()->only_servers_encode ()) { - for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) { - _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ()))); - } - } - - _writer->set_encoder_threads (_threads.size ()); - if (!ServerFinder::instance()->disabled ()) { _server_found_connection = ServerFinder::instance()->ServersListChanged.connect (boost::bind (&Encoder::servers_list_changed, this)); } @@ -292,6 +269,12 @@ void Encoder::encoder_thread (optional server) try { + if (server) { + LOG_TIMING ("start-encoder-thread thread=%1 server=%2", boost::this_thread::get_id (), server->host_name ()); + } else { + LOG_TIMING ("start-encoder-thread thread=%1 server=localhost", boost::this_thread::get_id ()); + } + /* Number of seconds that we currently wait between attempts to connect to the server; not relevant for localhost encodings. @@ -380,7 +363,21 @@ void Encoder::servers_list_changed () { terminate_threads (); + + /* XXX: could re-use threads */ + + if (!Config::instance()->only_servers_encode ()) { + for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) { + _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ()))); + } + } + BOOST_FOREACH (ServerDescription i, ServerFinder::instance()->servers ()) { - add_worker_threads (i); + LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), i.threads(), i.host_name ()); + for (int j = 0; j < i.threads(); ++j) { + _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, i))); + } } + + _writer->set_encoder_threads (_threads.size ()); } diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 06a963a21..e9daab521 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -77,7 +77,6 @@ private: void encoder_thread (boost::optional); void terminate_threads (); - void add_worker_threads (ServerDescription); void servers_list_changed (); /** Film that we are encoding */ -- 2.30.2