X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fserver_finder.cc;h=3eec6597b55df1d92125b1785ad2998a104adb33;hb=ddef0fb991ee50275e801c0cd813b7d74ead6ddf;hp=a189ae8027dbcb44762b822d281ecc089335ca8e;hpb=7ae514af0aea1b953a93f88d5507e6c1dd675908;p=dcpomatic.git diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index a189ae802..3eec6597b 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -41,11 +41,11 @@ ServerFinder* ServerFinder::_instance = 0; ServerFinder::ServerFinder () : _disabled (false) - , _broadcast_thread (0) + , _search_thread (0) , _listen_thread (0) , _stop (false) { - _broadcast_thread = new boost::thread (boost::bind (&ServerFinder::broadcast_thread, this)); + _search_thread = new boost::thread (boost::bind (&ServerFinder::search_thread, this)); _listen_thread = new boost::thread (boost::bind (&ServerFinder::listen_thread, this)); Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1)); } @@ -54,15 +54,15 @@ ServerFinder::~ServerFinder () { _stop = true; - _broadcast_thread->interrupt (); - _broadcast_thread->join (); + _search_condition.notify_all (); + _search_thread->join (); _listen_io_service.stop (); _listen_thread->join (); } void -ServerFinder::broadcast_thread () +ServerFinder::search_thread () try { boost::system::error_code error; @@ -106,11 +106,8 @@ try } } - try { - boost::thread::sleep (boost::get_system_time() + boost::posix_time::seconds (10)); - } catch (boost::thread_interrupted& e) { - return; - } + boost::mutex::scoped_lock lm (_search_condition_mutex); + _search_condition.timed_wait (lm, boost::get_system_time() + boost::posix_time::seconds (10)); } } catch (...) @@ -224,5 +221,12 @@ ServerFinder::config_changed (Config::Property what) _servers.clear (); } ServersListChanged (); + search_now (); } } + +void +ServerFinder::search_now () +{ + _search_condition.notify_all (); +}