Various thread cleanups.
authorCarl Hetherington <cth@carlh.net>
Thu, 30 Jan 2020 21:54:38 +0000 (22:54 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 30 Jan 2020 21:54:38 +0000 (22:54 +0100)
21 files changed:
src/lib/butler.cc
src/lib/butler.h
src/lib/checker.cc
src/lib/checker.h
src/lib/encode_server.cc
src/lib/encode_server.h
src/lib/encode_server_finder.cc
src/lib/encode_server_finder.h
src/lib/j2k_encoder.cc
src/lib/j2k_encoder.h
src/lib/job.cc
src/lib/job.h
src/lib/job_manager.cc
src/lib/job_manager.h
src/lib/update_checker.cc
src/lib/update_checker.h
src/lib/writer.cc
src/lib/writer.h
src/tools/dcpomatic_server.cc
src/wx/gl_video_view.cc
src/wx/gl_video_view.h

index 6062b0f21f67a9e09ba7a818a8e12285a67f2cff..20180330e5f68d2a048402328ccc32d7da64fd7b 100644 (file)
@@ -83,9 +83,9 @@ Butler::Butler (
           get_video() to be called in response to this signal.
        */
        _player_change_connection = _player->Change.connect (bind (&Butler::player_change, this, _1), boost::signals2::at_front);
           get_video() to be called in response to this signal.
        */
        _player_change_connection = _player->Change.connect (bind (&Butler::player_change, this, _1), boost::signals2::at_front);
-       _thread = new boost::thread (bind (&Butler::thread, this));
+       _thread = boost::thread (bind(&Butler::thread, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_thread->native_handle(), "butler");
+       pthread_setname_np (_thread.native_handle(), "butler");
 #endif
 
        /* Create some threads to do work on the PlayerVideos we are creating; at present this is used to
 #endif
 
        /* Create some threads to do work on the PlayerVideos we are creating; at present this is used to
@@ -110,13 +110,12 @@ Butler::~Butler ()
        _prepare_pool.join_all ();
        _prepare_service.stop ();
 
        _prepare_pool.join_all ();
        _prepare_service.stop ();
 
-       _thread->interrupt ();
+       _thread.interrupt ();
        try {
        try {
-               _thread->join ();
-       } catch (boost::thread_interrupted& e) {
-               /* No problem */
+               _thread.join ();
+       } catch (...) {
+
        }
        }
-       delete _thread;
 }
 
 /** Caller must hold a lock on _mutex */
 }
 
 /** Caller must hold a lock on _mutex */
index ea43374434f033a5becfebc13f2fce09a6436d5c..0a0050e8ff90aa8f1aeb184bf531da457322efdb 100644 (file)
@@ -73,7 +73,7 @@ private:
        void seek_unlocked (dcpomatic::DCPTime position, bool accurate);
 
        boost::shared_ptr<Player> _player;
        void seek_unlocked (dcpomatic::DCPTime position, bool accurate);
 
        boost::shared_ptr<Player> _player;
-       boost::thread* _thread;
+       boost::thread _thread;
 
        VideoRingBuffers _video;
        AudioRingBuffers _audio;
 
        VideoRingBuffers _video;
        AudioRingBuffers _audio;
index 2d15dd3f1e1adae3fed945674cfff9676498d3ba..c32462b42b57c8bd9c4da0e448e950adb8e6f4ed 100644 (file)
@@ -28,8 +28,7 @@ using boost::bind;
 using boost::ref;
 
 Checker::Checker (int period)
 using boost::ref;
 
 Checker::Checker (int period)
-       : _thread (0)
-       , _terminate (false)
+       : _terminate (false)
        , _ok (true)
        , _period (period)
 {
        , _ok (true)
        , _period (period)
 {
@@ -39,7 +38,7 @@ Checker::Checker (int period)
 void
 Checker::run ()
 {
 void
 Checker::run ()
 {
-       _thread = new boost::thread (boost::bind (&Checker::thread, this));
+       _thread = boost::thread (boost::bind(&Checker::thread, this));
 }
 
 Checker::~Checker ()
 }
 
 Checker::~Checker ()
@@ -49,20 +48,14 @@ Checker::~Checker ()
                _terminate = true;
        }
 
                _terminate = true;
        }
 
-       if (_thread) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_thread->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               _thread->interrupt ();
+       if (_thread.joinable()) {
+               _thread.interrupt ();
                try {
                try {
-                       if (_thread->joinable ()) {
-                               _thread->join ();
-                       }
-               } catch (boost::thread_interrupted& e) {
-                       /* No problem */
+                       _thread.join ();
+               } catch (...) {
+
                }
        }
                }
        }
-       delete _thread;
 }
 
 void
 }
 
 void
index fee3fc3d92595aaa4deb01fdd93fbdecb2a681d0..8b80d8527a1f183c8b235bc8cab4e97ab7530b1d 100644 (file)
@@ -54,7 +54,7 @@ private:
 
        void thread ();
 
 
        void thread ();
 
-       boost::thread* _thread;
+       boost::thread _thread;
        mutable boost::mutex _mutex;
        bool _terminate;
        bool _ok;
        mutable boost::mutex _mutex;
        bool _terminate;
        bool _ok;
index 314f8f68dcccda973d04ac683064fc2f25dec6de..e79f82b629e197d783f51a8201c05fc3316d6838 100644 (file)
@@ -87,14 +87,12 @@ EncodeServer::~EncodeServer ()
                _full_condition.notify_all ();
        }
 
                _full_condition.notify_all ();
        }
 
-       BOOST_FOREACH (boost::thread* i, _worker_threads) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(i->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (i->joinable ()) {
-                       i->join ();
+       BOOST_FOREACH (boost::thread& i, _worker_threads) {
+               try {
+                       i.join ();
+               } catch (...) {
+
                }
                }
-               delete i;
        }
 
        {
        }
 
        {
@@ -107,14 +105,12 @@ EncodeServer::~EncodeServer ()
        }
 
        _broadcast.io_service.stop ();
        }
 
        _broadcast.io_service.stop ();
-       if (_broadcast.thread) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_broadcast.thread->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (_broadcast.thread->joinable ()) {
-                       _broadcast.thread->join ();
+       if (_broadcast.thread.joinable()) {
+               try {
+                       _broadcast.thread.join ();
+               } catch (...) {
+
                }
                }
-               delete _broadcast.thread;
        }
 }
 
        }
 }
 
@@ -237,16 +233,15 @@ EncodeServer::run ()
        }
 
        for (int i = 0; i < _num_threads; ++i) {
        }
 
        for (int i = 0; i < _num_threads; ++i) {
-               thread* t = new thread (bind (&EncodeServer::worker_thread, this));
+               _worker_threads.push_back (thread(bind(&EncodeServer::worker_thread, this)));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-               pthread_setname_np (t->native_handle(), "encode-server-worker");
+               pthread_setname_np (_worker_threads.back().native_handle(), "encode-server-worker");
 #endif
 #endif
-               _worker_threads.push_back (t);
        }
 
        }
 
-       _broadcast.thread = new thread (bind (&EncodeServer::broadcast_thread, this));
+       _broadcast.thread = thread (bind(&EncodeServer::broadcast_thread, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_broadcast.thread->native_handle(), "encode-server-broadcast");
+       pthread_setname_np (_broadcast.thread.native_handle(), "encode-server-broadcast");
 #endif
 
        Server::run ();
 #endif
 
        Server::run ();
index 14dc77398a660b730258974cc7b3fee8f9f2d74e..40e84ad6029d9d7ff28d6f942923e989ffe7f549 100644 (file)
@@ -54,7 +54,7 @@ private:
        void broadcast_thread ();
        void broadcast_received ();
 
        void broadcast_thread ();
        void broadcast_received ();
 
-       std::vector<boost::thread *> _worker_threads;
+       std::vector<boost::thread> _worker_threads;
        std::list<boost::shared_ptr<Socket> > _queue;
        boost::condition _full_condition;
        boost::condition _empty_condition;
        std::list<boost::shared_ptr<Socket> > _queue;
        boost::condition _full_condition;
        boost::condition _empty_condition;
@@ -64,12 +64,11 @@ private:
        struct Broadcast {
 
                Broadcast ()
        struct Broadcast {
 
                Broadcast ()
-                       : thread (0)
-                       , socket (0)
+                       : socket (0)
                {}
 
                boost::mutex mutex;
                {}
 
                boost::mutex mutex;
-               boost::thread* thread;
+               boost::thread thread;
                boost::asio::ip::udp::socket* socket;
                char buffer[64];
                boost::asio::ip::udp::endpoint send_endpoint;
                boost::asio::ip::udp::socket* socket;
                char buffer[64];
                boost::asio::ip::udp::endpoint send_endpoint;
index 6cdd8ce3cc11adb05062c9fd8fdc8744588e33b5..52c8c89496bdec9b46bb5de1487b06d48907eed8 100644 (file)
@@ -45,9 +45,7 @@ using dcp::raw_convert;
 EncodeServerFinder* EncodeServerFinder::_instance = 0;
 
 EncodeServerFinder::EncodeServerFinder ()
 EncodeServerFinder* EncodeServerFinder::_instance = 0;
 
 EncodeServerFinder::EncodeServerFinder ()
-       : _search_thread (0)
-       , _listen_thread (0)
-       , _stop (false)
+       : _stop (false)
 {
        Config::instance()->Changed.connect (boost::bind (&EncodeServerFinder::config_changed, this, _1));
 }
 {
        Config::instance()->Changed.connect (boost::bind (&EncodeServerFinder::config_changed, this, _1));
 }
@@ -55,11 +53,11 @@ EncodeServerFinder::EncodeServerFinder ()
 void
 EncodeServerFinder::start ()
 {
 void
 EncodeServerFinder::start ()
 {
-       _search_thread = new boost::thread (boost::bind (&EncodeServerFinder::search_thread, this));
-       _listen_thread = new boost::thread (boost::bind (&EncodeServerFinder::listen_thread, this));
+       _search_thread = boost::thread (boost::bind(&EncodeServerFinder::search_thread, this));
+       _listen_thread = boost::thread (boost::bind(&EncodeServerFinder::listen_thread, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_search_thread->native_handle(), "encode-server-search");
-       pthread_setname_np (_listen_thread->native_handle(), "encode-server-listen");
+       pthread_setname_np (_search_thread.native_handle(), "encode-server-search");
+       pthread_setname_np (_listen_thread.native_handle(), "encode-server-listen");
 #endif
 }
 
 #endif
 }
 
@@ -75,28 +73,22 @@ EncodeServerFinder::stop ()
        _stop = true;
 
        _search_condition.notify_all ();
        _stop = true;
 
        _search_condition.notify_all ();
-       if (_search_thread) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_search_thread->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (_search_thread->joinable ()) {
-                       _search_thread->join ();
+       if (_search_thread.joinable()) {
+               try {
+                       _search_thread.join();
+               } catch (...) {
+
                }
        }
                }
        }
-       delete _search_thread;
-       _search_thread = 0;
 
        _listen_io_service.stop ();
 
        _listen_io_service.stop ();
-       if (_listen_thread) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_listen_thread->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (_listen_thread->joinable ()) {
-                       _listen_thread->join ();
+       if (_listen_thread.joinable()) {
+               try {
+                       _listen_thread.join ();
+               } catch (...) {
+
                }
        }
                }
        }
-       delete _listen_thread;
-       _listen_thread = 0;
 
        boost::mutex::scoped_lock lm (_servers_mutex);
        _servers.clear ();
 
        boost::mutex::scoped_lock lm (_servers_mutex);
        _servers.clear ();
index abfcc6d35c5512526aec86af38aeda773007a746..78b72fa9cc079e42706382bf58497ac193aa4724 100644 (file)
@@ -69,9 +69,9 @@ private:
        void config_changed (Config::Property what);
 
        /** Thread to periodically issue broadcasts and requests to find encoding servers */
        void config_changed (Config::Property what);
 
        /** Thread to periodically issue broadcasts and requests to find encoding servers */
-       boost::thread* _search_thread;
+       boost::thread _search_thread;
        /** Thread to listen to the responses from servers */
        /** Thread to listen to the responses from servers */
-       boost::thread* _listen_thread;
+       boost::thread _listen_thread;
 
        /** Available servers */
        std::list<EncodeServerDescription> _servers;
 
        /** Available servers */
        std::list<EncodeServerDescription> _servers;
index 5c3fd477ef16dfeefb63d90bdb13bdbdd156bd0a..96b5b86e78867b99d0cffc3414d1f458c7fac22c 100644 (file)
@@ -250,23 +250,17 @@ J2KEncoder::terminate_threads ()
        boost::mutex::scoped_lock threads_lock (_threads_mutex);
 
        int n = 0;
        boost::mutex::scoped_lock threads_lock (_threads_mutex);
 
        int n = 0;
-       for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
+       for (list<boost::thread>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
                /* Be careful not to throw in here otherwise _threads will not be clear()ed */
                LOG_GENERAL ("Terminating thread %1 of %2", n + 1, _threads.size ());
                /* Be careful not to throw in here otherwise _threads will not be clear()ed */
                LOG_GENERAL ("Terminating thread %1 of %2", n + 1, _threads.size ());
-               (*i)->interrupt ();
-               if (!(*i)->joinable()) {
-                       LOG_ERROR_NC ("About to join() a non-joinable thread");
-               }
+               i->interrupt ();
                try {
                try {
-                       (*i)->join ();
-               } catch (boost::thread_interrupted& e) {
-                       /* This is to be expected (I think?) */
+                       i->join ();
                } catch (exception& e) {
                        LOG_ERROR ("join() threw an exception: %1", e.what());
                } catch (...) {
                        LOG_ERROR_NC ("join() threw an exception");
                }
                } catch (exception& e) {
                        LOG_ERROR ("join() threw an exception: %1", e.what());
                } catch (...) {
                        LOG_ERROR_NC ("join() threw an exception");
                }
-               delete *i;
                LOG_GENERAL_NC ("Thread terminated");
                ++n;
        }
                LOG_GENERAL_NC ("Thread terminated");
                ++n;
        }
@@ -402,14 +396,13 @@ J2KEncoder::servers_list_changed ()
 
        if (!Config::instance()->only_servers_encode ()) {
                for (int i = 0; i < Config::instance()->master_encoding_threads (); ++i) {
 
        if (!Config::instance()->only_servers_encode ()) {
                for (int i = 0; i < Config::instance()->master_encoding_threads (); ++i) {
-                       boost::thread* t = new boost::thread (boost::bind (&J2KEncoder::encoder_thread, this, optional<EncodeServerDescription> ()));
+                       _threads.push_back (boost::thread(boost::bind(&J2KEncoder::encoder_thread, this, optional<EncodeServerDescription>())));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-                       pthread_setname_np (t->native_handle(), "encode-worker");
+                       pthread_setname_np (_threads.back().native_handle(), "encode-worker");
 #endif
 #endif
-                       _threads.push_back (t);
 #ifdef BOOST_THREAD_PLATFORM_WIN32
                        if (windows_xp) {
 #ifdef BOOST_THREAD_PLATFORM_WIN32
                        if (windows_xp) {
-                               SetThreadAffinityMask (t->native_handle(), 1 << i);
+                               SetThreadAffinityMask (_threads.back().native_handle(), 1 << i);
                        }
 #endif
                }
                        }
 #endif
                }
@@ -422,7 +415,7 @@ J2KEncoder::servers_list_changed ()
 
                LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), i.threads(), i.host_name ());
                for (int j = 0; j < i.threads(); ++j) {
 
                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 (&J2KEncoder::encoder_thread, this, i)));
+                       _threads.push_back (boost::thread(boost::bind(&J2KEncoder::encoder_thread, this, i)));
                }
        }
 
                }
        }
 
index b723ca88f7afe2211364f25b817360ec639d4872..b57c4df7e3692501a64256730ab2928b1a92a692 100644 (file)
@@ -89,7 +89,7 @@ private:
 
        /** Mutex for _threads */
        mutable boost::mutex _threads_mutex;
 
        /** Mutex for _threads */
        mutable boost::mutex _threads_mutex;
-       std::list<boost::thread *> _threads;
+       std::list<boost::thread> _threads;
        mutable boost::mutex _queue_mutex;
        std::list<boost::shared_ptr<DCPVideo> > _queue;
        /** condition to manage thread wakeups when we have nothing to do */
        mutable boost::mutex _queue_mutex;
        std::list<boost::shared_ptr<DCPVideo> > _queue;
        /** condition to manage thread wakeups when we have nothing to do */
index 8966a65e700eb84b8f3945eb7d81987d8c88f7b5..04aa227b7a46c749f03c6ae56e6eb43a66645f38 100644 (file)
@@ -51,7 +51,6 @@ using namespace dcpomatic;
 /** @param film Associated film, or 0 */
 Job::Job (shared_ptr<const Film> film)
        : _film (film)
 /** @param film Associated film, or 0 */
 Job::Job (shared_ptr<const Film> film)
        : _film (film)
-       , _thread (0)
        , _state (NEW)
        , _start_time (0)
        , _sub_start_time (0)
        , _state (NEW)
        , _start_time (0)
        , _sub_start_time (0)
@@ -69,20 +68,16 @@ Job::~Job ()
 void
 Job::stop_thread ()
 {
 void
 Job::stop_thread ()
 {
-       if (_thread) {
-               _thread->interrupt ();
-               /* We can't use DCPOMATIC_ASSERT here as it may throw an exception */
-               if (_thread->joinable ()) {
-                       try {
-                               _thread->join ();
-                       } catch (...) {
-                               /* Too late to do anything about this */
-                       }
-               }
+       if (!_thread.joinable()) {
+               return;
        }
 
        }
 
-       delete _thread;
-       _thread = 0;
+       _thread.interrupt ();
+       try {
+               _thread.join ();
+       } catch (...) {
+               /* Too late to do anything about this */
+       }
 }
 
 /** Start the job in a separate thread, returning immediately */
 }
 
 /** Start the job in a separate thread, returning immediately */
@@ -92,9 +87,9 @@ Job::start ()
        set_state (RUNNING);
        _start_time = time (0);
        _sub_start_time = time (0);
        set_state (RUNNING);
        _start_time = time (0);
        _sub_start_time = time (0);
-       _thread = new boost::thread (boost::bind (&Job::run_wrapper, this));
+       _thread = boost::thread (boost::bind(&Job::run_wrapper, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_thread->native_handle(), "job-wrapper");
+       pthread_setname_np (_thread.native_handle(), "job-wrapper");
 #endif
 }
 
 #endif
 }
 
@@ -515,7 +510,7 @@ Job::remaining_time () const
 void
 Job::cancel ()
 {
 void
 Job::cancel ()
 {
-       if (!_thread) {
+       if (!_thread.joinable()) {
                return;
        }
 
                return;
        }
 
@@ -523,11 +518,8 @@ Job::cancel ()
                resume ();
        }
 
                resume ();
        }
 
-       _thread->interrupt ();
-       DCPOMATIC_ASSERT (_thread->joinable ());
-       _thread->join ();
-       delete _thread;
-       _thread = 0;
+       _thread.interrupt ();
+       _thread.join ();
 }
 
 /** @return true if the job was paused, false if it was not running */
 }
 
 /** @return true if the job was paused, false if it was not running */
index cb85059a61875c470a5a750d225fe51930dd7ee2..a0e988fc8ccd11df26983127e347691da43cd2f2 100644 (file)
@@ -121,7 +121,7 @@ private:
        void run_wrapper ();
        void set_progress_common (boost::optional<float> p);
 
        void run_wrapper ();
        void set_progress_common (boost::optional<float> p);
 
-       boost::thread* _thread;
+       boost::thread _thread;
 
        /** mutex for _state, _error*, _message */
        mutable boost::mutex _state_mutex;
 
        /** mutex for _state, _error*, _message */
        mutable boost::mutex _state_mutex;
index 26e2d28970a71c0f5a9d90b7582ed2738fd2fca0..d95f95a2481ba860ae4ee0c304d3190cf09f53f9 100644 (file)
@@ -46,7 +46,6 @@ JobManager* JobManager::_instance = 0;
 JobManager::JobManager ()
        : _terminate (false)
        , _paused (false)
 JobManager::JobManager ()
        : _terminate (false)
        , _paused (false)
-       , _scheduler (0)
 {
 
 }
 {
 
 }
@@ -54,9 +53,9 @@ JobManager::JobManager ()
 void
 JobManager::start ()
 {
 void
 JobManager::start ()
 {
-       _scheduler = new boost::thread (boost::bind (&JobManager::scheduler, this));
+       _scheduler = boost::thread (boost::bind(&JobManager::scheduler, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_scheduler->native_handle(), "job-scheduler");
+       pthread_setname_np (_scheduler.native_handle(), "job-scheduler");
 #endif
 }
 
 #endif
 }
 
@@ -72,16 +71,13 @@ JobManager::~JobManager ()
                _empty_condition.notify_all ();
        }
 
                _empty_condition.notify_all ();
        }
 
-       if (_scheduler) {
-               /* Ideally this would be a DCPOMATIC_ASSERT(_scheduler->joinable()) but we
-                  can't throw exceptions from a destructor.
-               */
-               if (_scheduler->joinable ()) {
-                       _scheduler->join ();
+       if (_scheduler.joinable()) {
+               try {
+                       _scheduler.join();
+               } catch (...) {
+
                }
        }
                }
        }
-
-       delete _scheduler;
 }
 
 shared_ptr<Job>
 }
 
 shared_ptr<Job>
index 2788fc657d2a00278e81ac55fb6c785059134dce..d4287f8746d667fd999d1d27450cdd9ef03150ae 100644 (file)
@@ -93,7 +93,7 @@ private:
        boost::shared_ptr<Job> _paused_job;
 
        boost::optional<std::string> _last_active_job;
        boost::shared_ptr<Job> _paused_job;
 
        boost::optional<std::string> _last_active_job;
-       boost::thread* _scheduler;
+       boost::thread _scheduler;
 
        static JobManager* _instance;
 };
 
        static JobManager* _instance;
 };
index 98e4078225d36f8619d4d34cd2e2fa3c3f24d639..82337f92016905420316ad19daa1d1779804ffcf 100644 (file)
@@ -56,7 +56,6 @@ UpdateChecker::UpdateChecker ()
        , _curl (0)
        , _state (NOT_RUN)
        , _emits (0)
        , _curl (0)
        , _state (NOT_RUN)
        , _emits (0)
-       , _thread (0)
        , _to_do (0)
        , _terminate (false)
 {
        , _to_do (0)
        , _terminate (false)
 {
@@ -74,9 +73,9 @@ UpdateChecker::UpdateChecker ()
 void
 UpdateChecker::start ()
 {
 void
 UpdateChecker::start ()
 {
-       _thread = new boost::thread (boost::bind (&UpdateChecker::thread, this));
+       _thread = boost::thread (boost::bind (&UpdateChecker::thread, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_thread->native_handle(), "update-checker");
+       pthread_setname_np (_thread.native_handle(), "update-checker");
 #endif
 }
 
 #endif
 }
 
@@ -88,15 +87,13 @@ UpdateChecker::~UpdateChecker ()
        }
 
        _condition.notify_all ();
        }
 
        _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 ();
+       if (_thread.joinable()) {
+               try {
+                       _thread.join ();
+               } catch (...) {
+
                }
        }
                }
        }
-       delete _thread;
 
        curl_easy_cleanup (_curl);
        delete[] _buffer;
 
        curl_easy_cleanup (_curl);
        delete[] _buffer;
index 5071bf4ec86840658e3adc246a161c31776c6034..78ca403038771c4c2c7adf0afb58fc15bc5c1e24 100644 (file)
@@ -93,7 +93,7 @@ private:
        boost::optional<std::string> _test;
        int _emits;
 
        boost::optional<std::string> _test;
        int _emits;
 
-       boost::thread* _thread;
+       boost::thread _thread;
        boost::mutex _process_mutex;
        boost::condition _condition;
        int _to_do;
        boost::mutex _process_mutex;
        boost::condition _condition;
        int _to_do;
index cc645c8b07c82451428f352054dad25bfeec71e1..d85db56894ccb59525ab18ef00303810a08d7ee6 100644 (file)
@@ -68,7 +68,6 @@ using namespace dcpomatic;
 Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        : _film (film)
        , _job (j)
 Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
        : _film (film)
        , _job (j)
-       , _thread (0)
        , _finish (false)
        , _queued_full_in_memory (0)
        /* These will be reset to sensible values when J2KEncoder is created */
        , _finish (false)
        , _queued_full_in_memory (0)
        /* These will be reset to sensible values when J2KEncoder is created */
@@ -107,9 +106,9 @@ Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
 void
 Writer::start ()
 {
 void
 Writer::start ()
 {
-       _thread = new boost::thread (boost::bind (&Writer::thread, this));
+       _thread = boost::thread (boost::bind(&Writer::thread, this));
 #ifdef DCPOMATIC_LINUX
 #ifdef DCPOMATIC_LINUX
-       pthread_setname_np (_thread->native_handle(), "writer");
+       pthread_setname_np (_thread.native_handle(), "writer");
 #endif
 }
 
 #endif
 }
 
@@ -465,7 +464,7 @@ void
 Writer::terminate_thread (bool can_throw)
 {
        boost::mutex::scoped_lock lock (_state_mutex);
 Writer::terminate_thread (bool can_throw)
 {
        boost::mutex::scoped_lock lock (_state_mutex);
-       if (_thread == 0) {
+       if (!_thread.joinable()) {
                return;
        }
 
                return;
        }
 
@@ -474,22 +473,17 @@ Writer::terminate_thread (bool can_throw)
        _full_condition.notify_all ();
        lock.unlock ();
 
        _full_condition.notify_all ();
        lock.unlock ();
 
-       if (_thread->joinable ()) {
-               _thread->join ();
-       }
+       _thread.join ();
 
        if (can_throw) {
                rethrow ();
        }
 
        if (can_throw) {
                rethrow ();
        }
-
-       delete _thread;
-       _thread = 0;
 }
 
 void
 Writer::finish ()
 {
 }
 
 void
 Writer::finish ()
 {
-       if (!_thread) {
+       if (!_thread.joinable()) {
                return;
        }
 
                return;
        }
 
index 5fe96a3ac94eee955cd9ac1429e86986e4da2f15..d304133dcb98f2c3d380e191fda78d0d0eef61b1 100644 (file)
@@ -131,8 +131,8 @@ private:
        std::vector<ReelWriter>::iterator _subtitle_reel;
        std::map<DCPTextTrack, std::vector<ReelWriter>::iterator> _caption_reels;
 
        std::vector<ReelWriter>::iterator _subtitle_reel;
        std::map<DCPTextTrack, std::vector<ReelWriter>::iterator> _caption_reels;
 
-       /** our thread, or 0 */
-       boost::thread* _thread;
+       /** our thread */
+       boost::thread _thread;
        /** true if our thread should finish */
        bool _finish;
        /** queue of things to write to disk */
        /** true if our thread should finish */
        bool _finish;
        /** queue of things to write to disk */
index 1554c02f4541ff11374b06ceddc41afffc5c43f3..8c6abed5babbbe19bfaca78c3313e6c02cbd48ed 100644 (file)
@@ -258,7 +258,6 @@ class App : public wxApp, public ExceptionStore
 public:
        App ()
                : wxApp ()
 public:
        App ()
                : wxApp ()
-               , _thread (0)
                , _icon (0)
        {}
 
                , _icon (0)
        {}
 
@@ -302,7 +301,7 @@ private:
 #else
                _icon = new TaskBarIcon;
 #endif
 #else
                _icon = new TaskBarIcon;
 #endif
-               _thread = new thread (bind (&App::main_thread, this));
+               _thread = thread (bind (&App::main_thread, this));
 
                Bind (wxEVT_TIMER, boost::bind (&App::check, this));
                _timer.reset (new wxTimer (this));
 
                Bind (wxEVT_TIMER, boost::bind (&App::check, this));
                _timer.reset (new wxTimer (this));
@@ -359,7 +358,7 @@ private:
                message_dialog (0, std_to_wx (m));
        }
 
                message_dialog (0, std_to_wx (m));
        }
 
-       boost::thread* _thread;
+       boost::thread _thread;
        TaskBarIcon* _icon;
        shared_ptr<wxTimer> _timer;
 };
        TaskBarIcon* _icon;
        shared_ptr<wxTimer> _timer;
 };
index d47ad87f48cdfbe788bd9151d04920c7cd5bb0ac..ebf4098e4c814693718e25be61a3b631776b7560 100644 (file)
@@ -57,7 +57,6 @@ GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent)
        : VideoView (viewer)
        , _have_storage (false)
        , _vsync_enabled (false)
        : VideoView (viewer)
        , _have_storage (false)
        , _vsync_enabled (false)
-       , _thread (0)
        , _playing (false)
        , _one_shot (false)
 {
        , _playing (false)
        , _one_shot (false)
 {
@@ -105,9 +104,12 @@ GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent)
 
 GLVideoView::~GLVideoView ()
 {
 
 GLVideoView::~GLVideoView ()
 {
-       _thread->interrupt ();
-       _thread->join ();
-       delete _thread;
+       try {
+               _thread.interrupt ();
+               _thread.join ();
+       } catch (...) {
+
+       }
 
        glDeleteTextures (1, &_id);
 }
 
        glDeleteTextures (1, &_id);
 }
@@ -386,7 +388,7 @@ GLVideoView::request_one_shot ()
 void
 GLVideoView::create ()
 {
 void
 GLVideoView::create ()
 {
-       if (!_thread) {
-               _thread = new boost::thread (boost::bind(&GLVideoView::thread, this));
+       if (!_thread.joinable()) {
+               _thread = boost::thread (boost::bind(&GLVideoView::thread, this));
        }
 }
        }
 }
index 2f3c8c2a1c40ccb715f1aa296d5f177ce5ed5d29..84d97c751f859bf3f24a7e08fffa9b5a1f9cae54 100644 (file)
@@ -68,7 +68,7 @@ private:
        boost::optional<dcp::Size> _size;
        bool _have_storage;
        bool _vsync_enabled;
        boost::optional<dcp::Size> _size;
        bool _have_storage;
        bool _vsync_enabled;
-       boost::thread* _thread;
+       boost::thread _thread;
 
        boost::mutex _playing_mutex;
        boost::condition _playing_condition;
 
        boost::mutex _playing_mutex;
        boost::condition _playing_condition;