Use a non-pointer boost::thread and a std::atomic for the stop flag.
authorCarl Hetherington <cth@carlh.net>
Thu, 30 Jan 2020 21:19:17 +0000 (22:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 30 Jan 2020 21:19:17 +0000 (22:19 +0100)
src/lib/hints.cc
src/lib/hints.h

index ad81e8d59eee1e7499e151c091e184c5d1f56331..6cb037ed0afd2ebd6bb865734de77eebd455f33f 100644 (file)
@@ -53,7 +53,6 @@ using namespace dcpomatic;
 
 Hints::Hints (weak_ptr<const Film> film)
        : _film (film)
 
 Hints::Hints (weak_ptr<const Film> film)
        : _film (film)
-       , _thread (0)
        , _long_ccap (false)
        , _overlap_ccap (false)
        , _too_many_ccap_lines (false)
        , _long_ccap (false)
        , _overlap_ccap (false)
        , _too_many_ccap_lines (false)
@@ -65,27 +64,22 @@ Hints::Hints (weak_ptr<const Film> film)
 void
 Hints::start ()
 {
 void
 Hints::start ()
 {
-       _thread = new boost::thread (bind(&Hints::thread, this));
+       _thread = boost::thread (bind(&Hints::thread, this));
 }
 
 Hints::~Hints ()
 {
 }
 
 Hints::~Hints ()
 {
-       if (!_thread) {
+       if (!_thread.joinable()) {
                return;
        }
 
        try {
                return;
        }
 
        try {
-               {
-                       boost::mutex::scoped_lock lm (_mutex);
-                       _stop = true;
-               }
-               _thread->interrupt ();
-               _thread->join ();
+               _stop = true;
+               _thread.interrupt ();
+               _thread.join ();
        } catch (...) {
 
        }
        } catch (...) {
 
        }
-
-       delete _thread;
 }
 
 void
 }
 
 void
@@ -279,11 +273,8 @@ Hints::thread ()
                        struct timeval now;
                        gettimeofday (&now, 0);
                        if ((seconds(now) - seconds(last_pulse)) > 1) {
                        struct timeval now;
                        gettimeofday (&now, 0);
                        if ((seconds(now) - seconds(last_pulse)) > 1) {
-                               {
-                                       boost::mutex::scoped_lock lm (_mutex);
-                                       if (_stop) {
-                                               break;
-                                       }
+                               if (_stop) {
+                                       break;
                                }
                                emit (bind (boost::ref(Pulse)));
                                last_pulse = now;
                                }
                                emit (bind (boost::ref(Pulse)));
                                last_pulse = now;
index e9a75fb14dabc17664d2451ca8bf5c9d71cae479..db7ee49b60007bf12f0ab5336df9efb409f36ce5 100644 (file)
@@ -49,13 +49,12 @@ private:
        void text (PlayerText text, TextType type, dcpomatic::DCPTimePeriod period);
 
        boost::weak_ptr<const Film> _film;
        void text (PlayerText text, TextType type, dcpomatic::DCPTimePeriod period);
 
        boost::weak_ptr<const Film> _film;
-       boost::thread* _thread;
+       boost::thread _thread;
 
        bool _long_ccap;
        bool _overlap_ccap;
        bool _too_many_ccap_lines;
        boost::optional<dcpomatic::DCPTimePeriod> _last;
 
 
        bool _long_ccap;
        bool _overlap_ccap;
        bool _too_many_ccap_lines;
        boost::optional<dcpomatic::DCPTimePeriod> _last;
 
-       boost::mutex _mutex;
-       bool _stop;
+       boost::atomic<bool> _stop;
 };
 };