diff options
author | Max Kellermann <max@musicpd.org> | 2018-04-26 16:07:15 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-04-26 16:18:18 +0200 |
commit | 7d546f80f9b1724bf0e240a896cb0bc8175b78af (patch) | |
tree | 90ca97d9c49268860cf3ea801d196cc03beb5dfc /src/output | |
parent | 5dfdc15f932c52d499d1938a4a5e063a1d9ff3ce (diff) |
output/alsa: merge Activate() and UnlockActivate()
Prepare to make the "active" attribute thread-safe.
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/plugins/AlsaOutputPlugin.cxx | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 2f51ef8d5..5eae7928f 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -233,28 +233,20 @@ private: * #EventLoop. Before calling this, filling the ring buffer * has no effect; nothing will be played, and no code will be * run on #EventLoop's thread. - */ - void Activate() noexcept { - if (active) - return; - - active = true; - defer_invalidate_sockets.Schedule(); - } - - /** - * Wrapper for Activate() which unlocks our mutex. Call this - * if you're holding the mutex. + * + * Caller must hold the mutex. * * @return true if Activate() was called, false if the mutex * was never unlocked */ - bool UnlockActivate() noexcept { + bool Activate() noexcept { if (active) return false; + active = true; + const ScopeUnlock unlock(mutex); - Activate(); + defer_invalidate_sockets.Schedule(); return true; } @@ -767,7 +759,7 @@ AlsaOutput::Drain() drain = true; - UnlockActivate(); + Activate(); while (drain) { if (error) @@ -853,7 +845,7 @@ AlsaOutput::Play(const void *chunk, size_t size) /* now that the ring_buffer is full, we can activate the socket handlers to trigger the first snd_pcm_writei() */ - if (UnlockActivate()) + if (Activate()) /* since everything may have changed while the mutex was unlocked, we need to skip the cond.wait() call below and check the new |