diff options
author | Max Kellermann <max@musicpd.org> | 2017-02-10 22:41:11 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-01-07 17:20:26 +0100 |
commit | 8649ea3d6fcbad110ecb668b8485cf4b8b45caba (patch) | |
tree | 0ad6948c8f77286aea01d524a2ca16220983139b /src/player | |
parent | 752ff12c37741d7b2bc52619529dabb59e91a998 (diff) |
thread/Thread: use BoundMethod
Diffstat (limited to 'src/player')
-rw-r--r-- | src/player/Control.cxx | 1 | ||||
-rw-r--r-- | src/player/Control.hxx | 3 | ||||
-rw-r--r-- | src/player/Thread.cxx | 74 |
3 files changed, 40 insertions, 38 deletions
diff --git a/src/player/Control.cxx b/src/player/Control.cxx index b6c3688f4..013b57bf5 100644 --- a/src/player/Control.cxx +++ b/src/player/Control.cxx @@ -37,6 +37,7 @@ PlayerControl::PlayerControl(PlayerListener &_listener, buffer_chunks(_buffer_chunks), buffered_before_play(_buffered_before_play), configured_audio_format(_configured_audio_format), + thread(BIND_THIS_METHOD(RunThread)), replay_gain_config(_replay_gain_config) { } diff --git a/src/player/Control.hxx b/src/player/Control.hxx index e5023f0a9..39e24e4f8 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -537,6 +537,9 @@ public: void ApplyEnabled() override { LockUpdateAudio(); } + +private: + void RunThread(); }; #endif diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 913e541e1..58883307d 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -1147,91 +1147,89 @@ do_play(PlayerControl &pc, DecoderControl &dc, player.Run(); } -static void -player_task(void *arg) +void +PlayerControl::RunThread() { - PlayerControl &pc = *(PlayerControl *)arg; - SetThreadName("player"); - DecoderControl dc(pc.mutex, pc.cond, - pc.configured_audio_format, - pc.replay_gain_config); + DecoderControl dc(mutex, cond, + configured_audio_format, + replay_gain_config); decoder_thread_start(dc); - MusicBuffer buffer(pc.buffer_chunks); + MusicBuffer buffer(buffer_chunks); - pc.Lock(); + Lock(); while (1) { - switch (pc.command) { + switch (command) { case PlayerCommand::SEEK: case PlayerCommand::QUEUE: - assert(pc.next_song != nullptr); + assert(next_song != nullptr); - pc.Unlock(); - do_play(pc, dc, buffer); - pc.listener.OnPlayerSync(); - pc.Lock(); + Unlock(); + do_play(*this, dc, buffer); + listener.OnPlayerSync(); + Lock(); break; case PlayerCommand::STOP: - pc.Unlock(); - pc.outputs.Cancel(); - pc.Lock(); + Unlock(); + outputs.Cancel(); + Lock(); /* fall through */ case PlayerCommand::PAUSE: - delete pc.next_song; - pc.next_song = nullptr; + delete next_song; + next_song = nullptr; - pc.CommandFinished(); + CommandFinished(); break; case PlayerCommand::CLOSE_AUDIO: - pc.Unlock(); + Unlock(); - pc.outputs.Release(); + outputs.Release(); - pc.Lock(); - pc.CommandFinished(); + Lock(); + CommandFinished(); assert(buffer.IsEmptyUnsafe()); break; case PlayerCommand::UPDATE_AUDIO: - pc.Unlock(); - pc.outputs.EnableDisable(); - pc.Lock(); - pc.CommandFinished(); + Unlock(); + outputs.EnableDisable(); + Lock(); + CommandFinished(); break; case PlayerCommand::EXIT: - pc.Unlock(); + Unlock(); dc.Quit(); - pc.outputs.Close(); + outputs.Close(); - pc.LockCommandFinished(); + LockCommandFinished(); return; case PlayerCommand::CANCEL: - delete pc.next_song; - pc.next_song = nullptr; + delete next_song; + next_song = nullptr; - pc.CommandFinished(); + CommandFinished(); break; case PlayerCommand::REFRESH: /* no-op when not playing */ - pc.CommandFinished(); + CommandFinished(); break; case PlayerCommand::NONE: - pc.Wait(); + Wait(); break; } } @@ -1242,5 +1240,5 @@ StartPlayerThread(PlayerControl &pc) { assert(!pc.thread.IsDefined()); - pc.thread.Start(player_task, &pc); + pc.thread.Start(); } |