Commit 15a54230 authored by Max Kellermann's avatar Max Kellermann

player/Thread: move unlock call down

Eliminate more unlock/lock transitions, making the code more robust.
parent f0d18488
...@@ -989,23 +989,23 @@ Player::Run() noexcept ...@@ -989,23 +989,23 @@ Player::Run() noexcept
break; break;
} }
pc.Unlock();
if (buffering) { if (buffering) {
/* buffering at the start of the song - wait /* buffering at the start of the song - wait
until the buffer is large enough, to until the buffer is large enough, to
prevent stuttering on slow machines */ prevent stuttering on slow machines */
if (pipe->GetSize() < pc.buffered_before_play && if (pipe->GetSize() < pc.buffered_before_play &&
!dc.LockIsIdle()) { !dc.IsIdle()) {
/* not enough decoded buffer space yet */ /* not enough decoded buffer space yet */
if (!paused && output_open && {
pc.outputs.Check() < 4 && const ScopeUnlock unlock(pc.mutex);
!SendSilence()) if (!paused && output_open &&
break; pc.outputs.Check() < 4 &&
!SendSilence())
break;
}
pc.Lock();
/* XXX race condition: check decoder again */ /* XXX race condition: check decoder again */
dc.WaitForDecoder(); dc.WaitForDecoder();
continue; continue;
...@@ -1018,8 +1018,6 @@ Player::Run() noexcept ...@@ -1018,8 +1018,6 @@ Player::Run() noexcept
if (decoder_starting) { if (decoder_starting) {
/* wait until the decoder is initialized completely */ /* wait until the decoder is initialized completely */
pc.Lock();
if (!CheckDecoderStartup()) { if (!CheckDecoderStartup()) {
pc.Unlock(); pc.Unlock();
break; break;
...@@ -1028,13 +1026,12 @@ Player::Run() noexcept ...@@ -1028,13 +1026,12 @@ Player::Run() noexcept
continue; continue;
} }
if (dc.LockIsIdle() && queued && dc.pipe == pipe) { if (dc.IsIdle() && queued && dc.pipe == pipe) {
/* the decoder has finished the current song; /* the decoder has finished the current song;
make it decode the next song */ make it decode the next song */
assert(dc.pipe == nullptr || dc.pipe == pipe); assert(dc.pipe == nullptr || dc.pipe == pipe);
const std::lock_guard<Mutex> lock(pc.mutex);
StartDecoder(*new MusicPipe()); StartDecoder(*new MusicPipe());
} }
...@@ -1043,7 +1040,7 @@ Player::Run() noexcept ...@@ -1043,7 +1040,7 @@ Player::Run() noexcept
!pc.border_pause && !pc.border_pause &&
IsDecoderAtNextSong() && IsDecoderAtNextSong() &&
xfade_state == CrossFadeState::UNKNOWN && xfade_state == CrossFadeState::UNKNOWN &&
!dc.LockIsStarting()) { !dc.IsStarting()) {
/* enable cross fading in this song? if yes, /* enable cross fading in this song? if yes,
calculate how many chunks will be required calculate how many chunks will be required
for it */ for it */
...@@ -1065,6 +1062,8 @@ Player::Run() noexcept ...@@ -1065,6 +1062,8 @@ Player::Run() noexcept
xfade_state = CrossFadeState::DISABLED; xfade_state = CrossFadeState::DISABLED;
} }
pc.Unlock();
if (paused) { if (paused) {
pc.Lock(); pc.Lock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment