Fix bugs in thread termination causing occasional pthread
[dcpomatic.git] / src / lib / update_checker.cc
index 8aeca030bf79f8ba4a7a599ebcce4bf1e11bda88..0fad330fd58ccd1b9942db4c47bf491c9757826a 100644 (file)
@@ -56,13 +56,12 @@ UpdateChecker::UpdateChecker ()
        , _curl (0)
        , _state (NOT_RUN)
        , _emits (0)
-       , _thread (0)
        , _to_do (0)
        , _terminate (false)
 {
        _curl = curl_easy_init ();
 
-       curl_easy_setopt (_curl, CURLOPT_URL, "http://dcpomatic.com/update");
+       curl_easy_setopt (_curl, CURLOPT_URL, "https://dcpomatic.com/update");
        curl_easy_setopt (_curl, CURLOPT_WRITEFUNCTION, write_callback_wrapper);
        curl_easy_setopt (_curl, CURLOPT_WRITEDATA, this);
        curl_easy_setopt (_curl, CURLOPT_TIMEOUT, 20);
@@ -74,26 +73,25 @@ UpdateChecker::UpdateChecker ()
 void
 UpdateChecker::start ()
 {
-       _thread = new boost::thread (boost::bind (&UpdateChecker::thread, this));
+       _thread = boost::thread (boost::bind (&UpdateChecker::thread, this));
+#ifdef DCPOMATIC_LINUX
+       pthread_setname_np (_thread.native_handle(), "update-checker");
+#endif
 }
 
 UpdateChecker::~UpdateChecker ()
 {
+       boost::this_thread::disable_interruption dis;
+
        {
                boost::mutex::scoped_lock lm (_process_mutex);
                _terminate = true;
        }
 
        _condition.notify_all ();
-       if (_thread) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_thread->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (_thread->joinable ()) {
-                       _thread->join ();
-               }
-       }
-       delete _thread;
+       try {
+               _thread.join ();
+       } catch (...) {}
 
        curl_easy_cleanup (_curl);
        delete[] _buffer;
@@ -158,7 +156,7 @@ UpdateChecker::thread ()
                                _stable = stable;
                        }
 
-                       if (version_less_than (dcpomatic_version, test)) {
+                       if (!test.empty() && version_less_than (dcpomatic_version, test)) {
                                _test = test;
                        }