diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-20 20:27:19 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-12-21 10:25:40 +0100 |
commit | a431274b3209a366c924f6204f3a5b0e37f8536f (patch) | |
tree | 554802fa94e2b11cd808391e139f8592b9100aee /src/player/Control.hxx | |
parent | 994c9a01e327c6ef379ff7ea7530321d3bdfe0fd (diff) |
player/Control: add "occupied" flag to skip REFRESH
Reduces main thread contention. Avoids blocking the main thread in
"status" commands.
Diffstat (limited to 'src/player/Control.hxx')
-rw-r--r-- | src/player/Control.hxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 2eae62313..073bbac90 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -185,6 +185,29 @@ struct PlayerControl final : AudioOutputClient { */ bool border_pause = false; + /** + * If this flag is set, then the player thread is currently + * occupied and will not be able to respond quickly to + * commands (e.g. waiting for the decoder thread to finish + * seeking). This is used to skip #PlayerCommand::REFRESH to + * avoid blocking the main thread. + */ + bool occupied = false; + + struct ScopeOccupied { + PlayerControl &pc; + + explicit ScopeOccupied(PlayerControl &_pc) noexcept:pc(_pc) { + assert(!pc.occupied); + pc.occupied = true; + } + + ~ScopeOccupied() noexcept { + assert(pc.occupied); + pc.occupied = false; + } + }; + AudioFormat audio_format; uint16_t bit_rate; |