player/Control: add "occupied" flag to skip REFRESH

Reduces main thread contention.  Avoids blocking the main thread in
"status" commands.
This commit is contained in:
Max Kellermann
2017-12-20 20:27:19 +01:00
parent 994c9a01e3
commit a431274b32
3 changed files with 30 additions and 1 deletions

View File

@@ -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;