diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-09-01 20:56:58 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-09-01 20:56:58 +0100 |
| commit | 0df83d7ba261cdbb5be62db34dae7b972e05ddd9 (patch) | |
| tree | 62e81768778f7cbe071d9a7ed90938a9dabaa356 /src | |
| parent | 6904ca547ce503c9ea06b4def9b9a716068e493c (diff) | |
Don't start thread in constructor; tidy up thread in destructor (UpdateChecker).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/update_checker.cc | 25 | ||||
| -rw-r--r-- | src/lib/update_checker.h | 4 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/lib/update_checker.cc b/src/lib/update_checker.cc index 634328e6a..52dfce7f7 100644 --- a/src/lib/update_checker.cc +++ b/src/lib/update_checker.cc @@ -55,7 +55,9 @@ UpdateChecker::UpdateChecker () , _curl (0) , _state (NOT_RUN) , _emits (0) + , _thread (0) , _to_do (0) + , _terminate (false) { _curl = curl_easy_init (); @@ -66,13 +68,26 @@ UpdateChecker::UpdateChecker () string const agent = "dcpomatic/" + string (dcpomatic_version); curl_easy_setopt (_curl, CURLOPT_USERAGENT, agent.c_str ()); +} +void +UpdateChecker::start () +{ _thread = new boost::thread (boost::bind (&UpdateChecker::thread, this)); } UpdateChecker::~UpdateChecker () { - /* We are not cleaning up our thread, but hey well */ + { + boost::mutex::scoped_lock lm (_process_mutex); + _terminate = true; + } + + _condition.notify_all (); + if (_thread) { + _thread->join (); + } + delete _thread; curl_easy_cleanup (_curl); delete[] _buffer; @@ -93,9 +108,14 @@ UpdateChecker::thread () while (true) { /* Block until there is something to do */ boost::mutex::scoped_lock lock (_process_mutex); - while (_to_do == 0) { + while (_to_do == 0 && !_terminate) { _condition.wait (lock); } + + if (_terminate) { + return; + } + --_to_do; lock.unlock (); @@ -173,6 +193,7 @@ UpdateChecker::instance () { if (!_instance) { _instance = new UpdateChecker (); + _instance->start (); } return _instance; diff --git a/src/lib/update_checker.h b/src/lib/update_checker.h index b82be7808..b0eb62273 100644 --- a/src/lib/update_checker.h +++ b/src/lib/update_checker.h @@ -34,7 +34,6 @@ struct update_checker_test; class UpdateChecker : public Signaller, public boost::noncopyable { public: - UpdateChecker (); ~UpdateChecker (); void run (); @@ -83,6 +82,8 @@ private: static bool version_less_than (std::string const & a, std::string const & b); + UpdateChecker (); + void start (); void set_state (State); void thread (); @@ -101,4 +102,5 @@ private: boost::mutex _process_mutex; boost::condition _condition; int _to_do; + bool _terminate; }; |
