Do EncodeServerFinder 'disable' in a more sensible way.
authorCarl Hetherington <cth@carlh.net>
Wed, 20 Jul 2016 09:47:49 +0000 (10:47 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 Jul 2016 09:47:49 +0000 (10:47 +0100)
Just stop the threads and clear the server list when
stop() is called.

ChangeLog
src/lib/encode_server_finder.cc
src/lib/encode_server_finder.h
src/lib/encoder.cc
src/tools/dcpomatic_cli.cc
test/test.cc

index 062677604504fd239fbb2b216cdf0420ad66bb65..c5645ba204a63c1c24c76b154427ddff4dc778bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2016-07-20  Carl Hetherington  <cth@carlh.net>
 
+       * Try to fix -r option to dcpomatic_cli.
+
        * Try to fix intermittent hangs with encoding servers.
 
 2016-07-14  Carl Hetherington  <cth@carlh.net>
index eebf404fafa9604116fb8cb0831b7458c7390e43..135a8bce8219539f676e37f18b3e05079f38b46c 100644 (file)
@@ -43,8 +43,7 @@ using boost::weak_ptr;
 EncodeServerFinder* EncodeServerFinder::_instance = 0;
 
 EncodeServerFinder::EncodeServerFinder ()
-       : _disabled (false)
-       , _search_thread (0)
+       : _search_thread (0)
        , _listen_thread (0)
        , _stop (false)
 {
@@ -58,7 +57,14 @@ EncodeServerFinder::start ()
        _listen_thread = new boost::thread (boost::bind (&EncodeServerFinder::listen_thread, this));
 }
 
+
 EncodeServerFinder::~EncodeServerFinder ()
+{
+       stop ();
+}
+
+void
+EncodeServerFinder::stop ()
 {
        _stop = true;
 
@@ -71,6 +77,8 @@ EncodeServerFinder::~EncodeServerFinder ()
                        _search_thread->join ();
                }
        }
+       delete _search_thread;
+       _search_thread = 0;
 
        _listen_io_service.stop ();
        if (_listen_thread) {
@@ -81,6 +89,11 @@ EncodeServerFinder::~EncodeServerFinder ()
                        _listen_thread->join ();
                }
        }
+       delete _listen_thread;
+       _listen_thread = 0;
+
+       boost::mutex::scoped_lock lm (_servers_mutex);
+       _servers.clear ();
 }
 
 void
index 58c7677f66229c97a03ded812932a3c794a5054b..c639dfe3bf3aabdd641ee4295348699ca7cd2b0d 100644 (file)
@@ -37,13 +37,7 @@ public:
        static EncodeServerFinder* instance ();
        static void drop ();
 
-       void disable () {
-               _disabled = true;
-       }
-
-       bool disabled () const {
-               return _disabled;
-       }
+       void stop ();
 
        std::list<EncodeServerDescription> servers () const;
 
@@ -65,8 +59,6 @@ private:
 
        void config_changed (Config::Property what);
 
-       bool _disabled;
-
        /** Thread to periodically issue broadcasts and requests to find encoding servers */
        boost::thread* _search_thread;
        /** Thread to listen to the responses from servers */
index 652412ddf01d455941c8760db1b080cf2cef68eb..0c41d8d806a8ec9bf627a54b2ac579315edab074 100644 (file)
@@ -78,12 +78,10 @@ Encoder::~Encoder ()
 void
 Encoder::begin ()
 {
-       if (!EncodeServerFinder::instance()->disabled ()) {
-               weak_ptr<Encoder> wp = shared_from_this ();
-               _server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
-                       boost::bind (&Encoder::call_servers_list_changed, wp)
-                       );
-       }
+       weak_ptr<Encoder> wp = shared_from_this ();
+       _server_found_connection = EncodeServerFinder::instance()->ServersListChanged.connect (
+               boost::bind (&Encoder::call_servers_list_changed, wp)
+               );
 }
 
 /* We don't want the servers-list-changed callback trying to do things
index 1a0ffda0021ad0b069d10d9a5dce75927a74272e..096a3b11895ac20784fc226d78b87c984237bab8 100644 (file)
@@ -256,7 +256,7 @@ main (int argc, char* argv[])
        signal_manager = new SignalManager ();
 
        if (no_remote) {
-               EncodeServerFinder::instance()->disable ();
+               EncodeServerFinder::instance()->stop ();
        }
 
        if (json_port) {
index c57f76e61c7f98a97effb69622a682308a81ea35..7a759314d8ba4713a7333b32856889746f662044 100644 (file)
@@ -81,7 +81,7 @@ struct TestConfig
                Config::instance()->set_default_j2k_bandwidth (100000000);
                Config::instance()->set_log_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR);
 
-               EncodeServerFinder::instance()->disable ();
+               EncodeServerFinder::instance()->stop ();
 
                signal_manager = new TestSignalManager ();
        }