diff options
author | Max Kellermann <max@musicpd.org> | 2020-01-18 21:43:14 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-01-18 21:43:17 +0100 |
commit | 37f984ba743d6b4e4c24110ccc8a50058f808cf5 (patch) | |
tree | 0404f2bf5ab567708b60ad78d072b8d503ed3b4f | |
parent | cd612c4eef0afc45f2ef7268224a789d89eeda56 (diff) |
output/Control: avoid sending KILL twice
-rw-r--r-- | src/output/Control.cxx | 4 | ||||
-rw-r--r-- | src/output/Control.hxx | 9 | ||||
-rw-r--r-- | src/output/Thread.cxx | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/output/Control.cxx b/src/output/Control.cxx index a50ac5012..efcef67e4 100644 --- a/src/output/Control.cxx +++ b/src/output/Control.cxx @@ -377,7 +377,9 @@ AudioOutputControl::BeginDestroy() noexcept { if (thread.IsDefined()) { const std::lock_guard<Mutex> protect(mutex); - if (IsCommandFinished()) + if (!killed) { + killed = true; CommandAsync(Command::KILL); + } } } diff --git a/src/output/Control.hxx b/src/output/Control.hxx index 9c6d78f7e..b1e33793f 100644 --- a/src/output/Control.hxx +++ b/src/output/Control.hxx @@ -212,6 +212,15 @@ class AudioOutputControl { */ bool skip_delay; + /** + * Has Command::KILL already been sent? This field is only + * defined if `thread` is defined. It shall avoid sending the + * command twice. + * + * Protected by #mutex. + */ + bool killed; + public: /** * This mutex protects #open, #fail_timer, #pipe. diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 8362fac8c..18193c0e4 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -526,6 +526,8 @@ AudioOutputControl::StartThread() { assert(command == Command::NONE); + killed = false; + const ScopeUnlock unlock(mutex); thread.Start(); } |