summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-01-30 22:19:17 +0100
committerCarl Hetherington <cth@carlh.net>2020-01-30 22:19:17 +0100
commita1546fb6c4e59621d99271b8ca996e96a574f7b3 (patch)
tree72b99a6de8e521297e85f38b02f7e87160c76768 /src/lib
parent05f2028ec1280a98050dc22609879230337a35ef (diff)
Use a non-pointer boost::thread and a std::atomic for the stop flag.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/hints.cc23
-rw-r--r--src/lib/hints.h5
2 files changed, 9 insertions, 19 deletions
diff --git a/src/lib/hints.cc b/src/lib/hints.cc
index ad81e8d59..6cb037ed0 100644
--- a/src/lib/hints.cc
+++ b/src/lib/hints.cc
@@ -53,7 +53,6 @@ using namespace dcpomatic;
Hints::Hints (weak_ptr<const Film> film)
: _film (film)
- , _thread (0)
, _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 ()
{
- _thread = new boost::thread (bind(&Hints::thread, this));
+ _thread = boost::thread (bind(&Hints::thread, this));
}
Hints::~Hints ()
{
- if (!_thread) {
+ if (!_thread.joinable()) {
return;
}
try {
- {
- boost::mutex::scoped_lock lm (_mutex);
- _stop = true;
- }
- _thread->interrupt ();
- _thread->join ();
+ _stop = true;
+ _thread.interrupt ();
+ _thread.join ();
} catch (...) {
}
-
- delete _thread;
}
void
@@ -279,11 +273,8 @@ Hints::thread ()
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;
diff --git a/src/lib/hints.h b/src/lib/hints.h
index e9a75fb14..db7ee49b6 100644
--- a/src/lib/hints.h
+++ b/src/lib/hints.h
@@ -49,13 +49,12 @@ private:
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;
- boost::mutex _mutex;
- bool _stop;
+ boost::atomic<bool> _stop;
};