diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-04-03 12:50:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-04-19 23:04:32 +0100 |
| commit | 90c447e9200b9eef0f542b21fab1d0d9eebab733 (patch) | |
| tree | 8053d0ca393f5ecb8bac40ebef50f5af8c5053d6 /src | |
| parent | fe99d14e3047e9302e94db372923c92291016f1c (diff) | |
Try to stop Butler deadlocking on quit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/butler.cc | 9 | ||||
| -rw-r--r-- | src/lib/butler.h | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/butler.cc b/src/lib/butler.cc index 175846d63..01c1ec4f8 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.cc @@ -41,6 +41,7 @@ Butler::Butler (weak_ptr<const Film> film, shared_ptr<Player> player, AudioMappi , _finished (false) , _audio_mapping (audio_mapping) , _audio_channels (audio_channels) + , _stop_thread (false) { _player_video_connection = _player->Video.connect (bind (&Butler::video, this, _1, _2)); _player_audio_connection = _player->Audio.connect (bind (&Butler::audio, this, _1, _2)); @@ -50,6 +51,7 @@ Butler::Butler (weak_ptr<const Film> film, shared_ptr<Player> player, AudioMappi Butler::~Butler () { + _stop_thread = true; _thread->interrupt (); try { _thread->join (); @@ -61,12 +63,13 @@ Butler::~Butler () void Butler::thread () +try { while (true) { boost::mutex::scoped_lock lm (_mutex); /* Wait until we have something to do */ - while (_video.size() >= VIDEO_READAHEAD && !_pending_seek_position) { + while ((_video.size() >= VIDEO_READAHEAD && !_pending_seek_position) || _stop_thread) { _summon.wait (lm); } @@ -80,7 +83,7 @@ Butler::thread () while lm is unlocked, as in that state nothing will be added to _video. */ - while (_video.size() < VIDEO_READAHEAD && !_pending_seek_position) { + while (_video.size() < VIDEO_READAHEAD && !_pending_seek_position && !_stop_thread) { lm.unlock (); if (_player->pass ()) { _finished = true; @@ -91,6 +94,8 @@ Butler::thread () _arrived.notify_all (); } } +} catch (boost::thread_interrupted) { + /* The butler thread is being terminated */ } pair<shared_ptr<PlayerVideo>, DCPTime> diff --git a/src/lib/butler.h b/src/lib/butler.h index d6742dcfa..f48352448 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -65,6 +65,8 @@ private: AudioMapping _audio_mapping; int _audio_channels; + bool _stop_thread; + boost::signals2::scoped_connection _player_video_connection; boost::signals2::scoped_connection _player_audio_connection; boost::signals2::scoped_connection _player_changed_connection; |
