summaryrefslogtreecommitdiff
path: root/src/player/Thread.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-12-22 01:13:01 +0100
committerMax Kellermann <max@musicpd.org>2017-12-22 01:14:51 +0100
commit15a54230f1f13def5d3abcde5e8d13b9553ee1bb (patch)
tree0820b84724db083d453e18b386e2c62ce505e4f0 /src/player/Thread.cxx
parentf0d184884a4ba9e0432e5174599c3050869f0598 (diff)
player/Thread: move unlock call down
Eliminate more unlock/lock transitions, making the code more robust.
Diffstat (limited to 'src/player/Thread.cxx')
-rw-r--r--src/player/Thread.cxx25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx
index e62b04e69..4862be5a4 100644
--- a/src/player/Thread.cxx
+++ b/src/player/Thread.cxx
@@ -989,23 +989,23 @@ Player::Run() noexcept
break;
}
- pc.Unlock();
-
if (buffering) {
/* buffering at the start of the song - wait
until the buffer is large enough, to
prevent stuttering on slow machines */
if (pipe->GetSize() < pc.buffered_before_play &&
- !dc.LockIsIdle()) {
+ !dc.IsIdle()) {
/* not enough decoded buffer space yet */
- if (!paused && output_open &&
- pc.outputs.Check() < 4 &&
- !SendSilence())
- break;
+ {
+ const ScopeUnlock unlock(pc.mutex);
+ if (!paused && output_open &&
+ pc.outputs.Check() < 4 &&
+ !SendSilence())
+ break;
+ }
- pc.Lock();
/* XXX race condition: check decoder again */
dc.WaitForDecoder();
continue;
@@ -1018,8 +1018,6 @@ Player::Run() noexcept
if (decoder_starting) {
/* wait until the decoder is initialized completely */
- pc.Lock();
-
if (!CheckDecoderStartup()) {
pc.Unlock();
break;
@@ -1028,13 +1026,12 @@ Player::Run() noexcept
continue;
}
- if (dc.LockIsIdle() && queued && dc.pipe == pipe) {
+ if (dc.IsIdle() && queued && dc.pipe == pipe) {
/* the decoder has finished the current song;
make it decode the next song */
assert(dc.pipe == nullptr || dc.pipe == pipe);
- const std::lock_guard<Mutex> lock(pc.mutex);
StartDecoder(*new MusicPipe());
}
@@ -1043,7 +1040,7 @@ Player::Run() noexcept
!pc.border_pause &&
IsDecoderAtNextSong() &&
xfade_state == CrossFadeState::UNKNOWN &&
- !dc.LockIsStarting()) {
+ !dc.IsStarting()) {
/* enable cross fading in this song? if yes,
calculate how many chunks will be required
for it */
@@ -1065,6 +1062,8 @@ Player::Run() noexcept
xfade_state = CrossFadeState::DISABLED;
}
+ pc.Unlock();
+
if (paused) {
pc.Lock();