From 2e182e84c35c73f8d5b4f135ffa3550b7e70f66f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 3 Jan 2017 07:11:57 +0100 Subject: thread/Mutex: remove ScopeLock, use std::lock_guard directly --- src/output/Internal.hxx | 2 +- src/output/MultipleOutputs.cxx | 8 ++++---- src/output/OutputControl.cxx | 18 +++++++++--------- src/output/OutputState.cxx | 2 +- src/output/OutputThread.cxx | 2 +- src/output/plugins/RoarOutputPlugin.cxx | 12 ++++++------ src/output/plugins/httpd/HttpdClient.cxx | 4 ++-- src/output/plugins/httpd/HttpdInternal.hxx | 2 +- src/output/plugins/httpd/HttpdOutputPlugin.cxx | 12 ++++++------ src/output/plugins/sles/SlesOutputPlugin.cxx | 8 ++++---- 10 files changed, 35 insertions(+), 35 deletions(-) (limited to 'src/output') diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index ae030bc8f..0fd156803 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -440,7 +440,7 @@ public: gcc_pure bool LockIsChunkConsumed(const MusicChunk &chunk) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); return IsChunkConsumed(chunk); } diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index e56fe2f2a..74c299be0 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -109,12 +109,12 @@ MultipleOutputs::EnableDisable() /* parallel execution */ for (auto ao : outputs) { - const ScopeLock lock(ao->mutex); + const std::lock_guard lock(ao->mutex); ao->EnableDisableAsync(); } for (auto ao : outputs) { - const ScopeLock lock(ao->mutex); + const std::lock_guard lock(ao->mutex); ao->WaitForCommand(); } } @@ -123,7 +123,7 @@ bool MultipleOutputs::AllFinished() const { for (auto ao : outputs) { - const ScopeLock protect(ao->mutex); + const std::lock_guard protect(ao->mutex); if (ao->IsOpen() && !ao->IsCommandFinished()) return false; } @@ -215,7 +215,7 @@ MultipleOutputs::Open(const AudioFormat audio_format, std::exception_ptr first_error; for (auto ao : outputs) { - const ScopeLock lock(ao->mutex); + const std::lock_guard lock(ao->mutex); if (ao->IsEnabled()) enabled = true; diff --git a/src/output/OutputControl.cxx b/src/output/OutputControl.cxx index fd20a6dd2..8b22042df 100644 --- a/src/output/OutputControl.cxx +++ b/src/output/OutputControl.cxx @@ -65,7 +65,7 @@ AudioOutput::CommandWait(Command cmd) void AudioOutput::LockCommandWait(Command cmd) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); CommandWait(cmd); } @@ -162,7 +162,7 @@ AudioOutput::LockUpdate(const AudioFormat audio_format, const MusicPipe &mp, bool force) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (enabled && really_enabled) { if (force || !fail_timer.IsDefined() || @@ -178,7 +178,7 @@ AudioOutput::LockUpdate(const AudioFormat audio_format, void AudioOutput::LockPlay() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(allow_play); @@ -197,7 +197,7 @@ AudioOutput::LockPauseAsync() mixer_auto_close()) */ mixer_auto_close(mixer); - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(allow_play); if (IsOpen()) @@ -207,7 +207,7 @@ AudioOutput::LockPauseAsync() void AudioOutput::LockDrainAsync() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(allow_play); if (IsOpen()) @@ -217,7 +217,7 @@ AudioOutput::LockDrainAsync() void AudioOutput::LockCancelAsync() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (IsOpen()) { allow_play = false; @@ -228,7 +228,7 @@ AudioOutput::LockCancelAsync() void AudioOutput::LockAllowPlay() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); allow_play = true; if (IsOpen()) @@ -249,7 +249,7 @@ AudioOutput::LockCloseWait() { assert(!open || !fail_timer.IsDefined()); - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); CloseWait(); } @@ -270,7 +270,7 @@ AudioOutput::BeginDestroy() mixer_auto_close(mixer); if (thread.IsDefined()) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); CommandAsync(Command::KILL); } } diff --git a/src/output/OutputState.cxx b/src/output/OutputState.cxx index 981bb024a..a2dfc84e2 100644 --- a/src/output/OutputState.cxx +++ b/src/output/OutputState.cxx @@ -43,7 +43,7 @@ audio_output_state_save(BufferedOutputStream &os, { for (unsigned i = 0, n = outputs.Size(); i != n; ++i) { const AudioOutput &ao = outputs.Get(i); - const ScopeLock lock(ao.mutex); + const std::lock_guard lock(ao.mutex); os.Format(AUDIO_DEVICE_STATE "%d:%s\n", ao.IsEnabled(), ao.GetName()); diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index f0b2ab085..a6242704a 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -397,7 +397,7 @@ AudioOutput::Task() SetThreadTimerSlackUS(100); - const ScopeLock lock(mutex); + const std::lock_guard lock(mutex); while (true) { switch (command) { diff --git a/src/output/plugins/RoarOutputPlugin.cxx b/src/output/plugins/RoarOutputPlugin.cxx index cbfc9ffce..b3e71854b 100644 --- a/src/output/plugins/RoarOutputPlugin.cxx +++ b/src/output/plugins/RoarOutputPlugin.cxx @@ -92,7 +92,7 @@ RoarOutput::RoarOutput(const ConfigBlock &block) inline int RoarOutput::GetVolume() const { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (vss == nullptr || !alive) return -1; @@ -116,7 +116,7 @@ RoarOutput::SetVolume(unsigned volume) { assert(volume <= 100); - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (vss == nullptr || !alive) throw std::runtime_error("closed"); @@ -177,7 +177,7 @@ roar_use_audio_format(struct roar_audio_info *info, inline void RoarOutput::Open(AudioFormat &audio_format) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (roar_simple_connect(&con, host.empty() ? nullptr : host.c_str(), @@ -201,7 +201,7 @@ RoarOutput::Open(AudioFormat &audio_format) inline void RoarOutput::Close() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); alive = false; @@ -214,7 +214,7 @@ RoarOutput::Close() inline void RoarOutput::Cancel() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (vss == nullptr) return; @@ -306,7 +306,7 @@ RoarOutput::SendTag(const Tag &tag) if (vss == nullptr) return; - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); size_t cnt = 0; struct roar_keyval vals[32]; diff --git a/src/output/plugins/httpd/HttpdClient.cxx b/src/output/plugins/httpd/HttpdClient.cxx index e9cda85f0..02960932d 100644 --- a/src/output/plugins/httpd/HttpdClient.cxx +++ b/src/output/plugins/httpd/HttpdClient.cxx @@ -56,7 +56,7 @@ HttpdClient::Close() void HttpdClient::LockClose() { - const ScopeLock protect(httpd.mutex); + const std::lock_guard protect(httpd.mutex); Close(); } @@ -272,7 +272,7 @@ HttpdClient::GetBytesTillMetaData() const inline bool HttpdClient::TryWrite() { - const ScopeLock protect(httpd.mutex); + const std::lock_guard protect(httpd.mutex); assert(state == RESPONSE); diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index 74363110d..a1fb9669a 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -200,7 +200,7 @@ public: */ gcc_pure bool LockHasClients() const { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); return HasClients(); } diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 0d0433e32..4dbd17e7c 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -153,7 +153,7 @@ HttpdOutput::RunDeferred() /* this method runs in the IOThread; it broadcasts pages from our own queue to all clients */ - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); while (!pages.empty()) { Page *page = pages.front(); @@ -200,7 +200,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid) (void)address; #endif /* HAVE_WRAP */ - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); if (fd >= 0) { /* can we allow additional client */ @@ -296,7 +296,7 @@ httpd_output_open(AudioOutput *ao, AudioFormat &audio_format) { HttpdOutput *httpd = HttpdOutput::Cast(ao); - const ScopeLock protect(httpd->mutex); + const std::lock_guard protect(httpd->mutex); httpd->Open(audio_format); } @@ -324,7 +324,7 @@ httpd_output_close(AudioOutput *ao) { HttpdOutput *httpd = HttpdOutput::Cast(ao); - const ScopeLock protect(httpd->mutex); + const std::lock_guard protect(httpd->mutex); httpd->Close(); } @@ -496,7 +496,7 @@ HttpdOutput::SendTag(const Tag &tag) metadata = icy_server_metadata_page(tag, &types[0]); if (metadata != nullptr) { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); for (auto &client : clients) client.PushMetaData(metadata); } @@ -514,7 +514,7 @@ httpd_output_tag(AudioOutput *ao, const Tag &tag) inline void HttpdOutput::CancelAllClients() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); while (!pages.empty()) { Page *page = pages.front(); diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index 274af1864..a5eb24a41 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -319,7 +319,7 @@ SlesOutput::Play(const void *chunk, size_t size) pause = false; } - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(filled < BUFFER_SIZE); @@ -348,7 +348,7 @@ SlesOutput::Play(const void *chunk, size_t size) inline void SlesOutput::Drain() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(filled < BUFFER_SIZE); @@ -371,7 +371,7 @@ SlesOutput::Cancel() FormatWarning(sles_domain, "AndroidSimpleBufferQueue.Clear() failed"); - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); n_queued = 0; filled = 0; } @@ -398,7 +398,7 @@ SlesOutput::Pause() inline void SlesOutput::PlayedCallback() { - const ScopeLock protect(mutex); + const std::lock_guard protect(mutex); assert(n_queued > 0); --n_queued; cond.signal(); -- cgit v1.2.3