Commit 2fc40e55 authored by Max Kellermann's avatar Max Kellermann

output/jack: eliminate "shutdown" flag, use only "error" (mutex protected)

parent d146bef7
...@@ -73,8 +73,6 @@ struct JackOutput final : AudioOutput { ...@@ -73,8 +73,6 @@ struct JackOutput final : AudioOutput {
jack_client_t *client; jack_client_t *client;
jack_ringbuffer_t *ringbuffer[MAX_PORTS]; jack_ringbuffer_t *ringbuffer[MAX_PORTS];
std::atomic_bool shutdown;
/** /**
* While this flag is set, the "process" callback generates * While this flag is set, the "process" callback generates
* silence. * silence.
...@@ -84,7 +82,7 @@ struct JackOutput final : AudioOutput { ...@@ -84,7 +82,7 @@ struct JackOutput final : AudioOutput {
/** /**
* Protects #error. * Protects #error.
*/ */
Mutex mutex; mutable Mutex mutex;
/** /**
* The error reported to the "on_info_shutdown" callback. * The error reported to the "on_info_shutdown" callback.
...@@ -108,7 +106,6 @@ struct JackOutput final : AudioOutput { ...@@ -108,7 +106,6 @@ struct JackOutput final : AudioOutput {
void Shutdown(std::exception_ptr e) noexcept { void Shutdown(std::exception_ptr e) noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard<Mutex> lock(mutex);
shutdown = true;
error = std::move(e); error = std::move(e);
} }
...@@ -144,7 +141,7 @@ struct JackOutput final : AudioOutput { ...@@ -144,7 +141,7 @@ struct JackOutput final : AudioOutput {
} }
std::chrono::steady_clock::duration Delay() const noexcept override { std::chrono::steady_clock::duration Delay() const noexcept override {
return pause && !shutdown return pause && !LockWasShutdown()
? std::chrono::seconds(1) ? std::chrono::seconds(1)
: std::chrono::steady_clock::duration::zero(); : std::chrono::steady_clock::duration::zero();
} }
...@@ -152,6 +149,12 @@ struct JackOutput final : AudioOutput { ...@@ -152,6 +149,12 @@ struct JackOutput final : AudioOutput {
size_t Play(const void *chunk, size_t size) override; size_t Play(const void *chunk, size_t size) override;
bool Pause() override; bool Pause() override;
private:
bool LockWasShutdown() const noexcept {
const std::lock_guard<Mutex> lock(mutex);
return !!error;
}
}; };
static constexpr Domain jack_output_domain("jack_output"); static constexpr Domain jack_output_domain("jack_output");
...@@ -408,7 +411,6 @@ JackOutput::Disconnect() noexcept ...@@ -408,7 +411,6 @@ JackOutput::Disconnect() noexcept
void void
JackOutput::Connect() JackOutput::Connect()
{ {
shutdown = false;
error = {}; error = {};
jack_status_t status; jack_status_t status;
...@@ -483,7 +485,7 @@ JackOutput::Stop() noexcept ...@@ -483,7 +485,7 @@ JackOutput::Stop() noexcept
if (client == nullptr) if (client == nullptr)
return; return;
if (shutdown) if (LockWasShutdown())
/* the connection has failed; close it */ /* the connection has failed; close it */
Disconnect(); Disconnect();
else else
...@@ -606,7 +608,7 @@ JackOutput::Open(AudioFormat &new_audio_format) ...@@ -606,7 +608,7 @@ JackOutput::Open(AudioFormat &new_audio_format)
{ {
pause = false; pause = false;
if (client != nullptr && shutdown) if (client != nullptr && LockWasShutdown())
Disconnect(); Disconnect();
if (client == nullptr) if (client == nullptr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment