diff --git a/src/MusicBuffer.cxx b/src/MusicBuffer.cxx index bae5a17f1..7e0498898 100644 --- a/src/MusicBuffer.cxx +++ b/src/MusicBuffer.cxx @@ -15,7 +15,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks) MusicChunkPtr MusicBuffer::Allocate() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return {buffer.Allocate(), MusicChunkDeleter(*this)}; } @@ -30,7 +30,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept chunk->next.reset(); chunk->other.reset(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(!chunk->other || !chunk->other->other); diff --git a/src/MusicBuffer.hxx b/src/MusicBuffer.hxx index 10db2c3fa..152d4b1b6 100644 --- a/src/MusicBuffer.hxx +++ b/src/MusicBuffer.hxx @@ -39,7 +39,7 @@ public: #endif bool IsFull() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return buffer.IsFull(); } diff --git a/src/MusicPipe.cxx b/src/MusicPipe.cxx index d0bf82955..485118db6 100644 --- a/src/MusicPipe.cxx +++ b/src/MusicPipe.cxx @@ -11,7 +11,7 @@ bool MusicPipe::Contains(const MusicChunk *chunk) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; for (const MusicChunk *i = head.get(); i != nullptr; i = i->next.get()) if (i == chunk) @@ -25,7 +25,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept MusicChunkPtr MusicPipe::Shift() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto chunk = std::move(head); if (chunk != nullptr) { @@ -65,7 +65,7 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept assert(!chunk->IsEmpty()); assert(chunk->length == 0 || chunk->audio_format.IsValid()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(size > 0 || !audio_format.IsDefined()); assert(!audio_format.IsDefined() || diff --git a/src/MusicPipe.hxx b/src/MusicPipe.hxx index 1165c9d3a..39ba30cfd 100644 --- a/src/MusicPipe.hxx +++ b/src/MusicPipe.hxx @@ -61,7 +61,7 @@ public: */ [[gnu::pure]] const MusicChunk *Peek() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return head.get(); } @@ -85,7 +85,7 @@ public: */ [[gnu::pure]] unsigned GetSize() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return size; } diff --git a/src/RemoteTagCache.cxx b/src/RemoteTagCache.cxx index 70edc3dde..fc1bc88c9 100644 --- a/src/RemoteTagCache.cxx +++ b/src/RemoteTagCache.cxx @@ -26,7 +26,7 @@ RemoteTagCache::~RemoteTagCache() noexcept void RemoteTagCache::Lookup(const std::string &uri) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; auto [tag, value] = map.insert_check(uri); if (value) { @@ -80,7 +80,7 @@ RemoteTagCache::ItemResolved(Item &item) noexcept void RemoteTagCache::InvokeHandlers() noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; while (!invoke_list.empty()) { auto &item = invoke_list.pop_front(); @@ -105,7 +105,7 @@ RemoteTagCache::Item::OnRemoteTag(Tag &&_tag) noexcept scanner.reset(); - const std::scoped_lock lock(parent.mutex); + const std::scoped_lock lock{parent.mutex}; parent.ItemResolved(*this); } @@ -117,6 +117,6 @@ RemoteTagCache::Item::OnRemoteTagError(std::exception_ptr e) noexcept scanner.reset(); - const std::scoped_lock lock(parent.mutex); + const std::scoped_lock lock{parent.mutex}; parent.ItemResolved(*this); } diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index 1e03a1348..08ab31d39 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -195,7 +195,7 @@ read_stream_art(Response &r, const std::string_view art_directory, std::size_t read_size = 0; if (buffer_size > 0) { - std::unique_lock lock(is->mutex); + std::unique_lock lock{is->mutex}; is->Seek(lock, offset); read_size = is->Read(lock, {buffer.get(), buffer_size}); } diff --git a/src/command/FingerprintCommands.cxx b/src/command/FingerprintCommands.cxx index 0893c3351..c3bc6d7f4 100644 --- a/src/command/FingerprintCommands.cxx +++ b/src/command/FingerprintCommands.cxx @@ -51,7 +51,7 @@ protected: } void CancelThread() noexcept override { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; cancel = true; cond.notify_one(); } @@ -188,7 +188,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is, return false; { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (cancel) throw StopDecoder(); } @@ -257,7 +257,7 @@ GetChromaprintCommand::OpenUri(const char *uri2) auto is = InputStream::Open(uri2, mutex); is->SetHandler(this); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { if (cancel) throw StopDecoder(); @@ -282,7 +282,7 @@ GetChromaprintCommand::Read(InputStream &is, if (dest.empty()) return 0; - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { if (cancel) diff --git a/src/db/update/Remove.cxx b/src/db/update/Remove.cxx index 45257e789..6050b16fe 100644 --- a/src/db/update/Remove.cxx +++ b/src/db/update/Remove.cxx @@ -20,7 +20,7 @@ UpdateRemoveService::RunDeferred() noexcept std::forward_list copy; { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; std::swap(uris, copy); } @@ -39,7 +39,7 @@ UpdateRemoveService::Remove(std::string &&uri) bool was_empty; { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; was_empty = uris.empty(); uris.emplace_front(std::move(uri)); } diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx index efa598565..78a222e70 100644 --- a/src/decoder/Bridge.cxx +++ b/src/decoder/Bridge.cxx @@ -95,7 +95,7 @@ NeedChunks(DecoderControl &dc, std::unique_lock &lock) noexcept static DecoderCommand LockNeedChunks(DecoderControl &dc) noexcept { - std::unique_lock lock(dc.mutex); + std::unique_lock lock{dc.mutex}; return NeedChunks(dc, lock); } @@ -135,7 +135,7 @@ DecoderBridge::FlushChunk() noexcept if (!chunk->IsEmpty()) dc.pipe->Push(std::move(chunk)); - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; dc.client_cond.notify_one(); } @@ -197,7 +197,7 @@ DecoderBridge::GetVirtualCommand() noexcept DecoderCommand DecoderBridge::LockGetVirtualCommand() noexcept { - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; return GetVirtualCommand(); } @@ -257,7 +257,7 @@ DecoderBridge::Ready(const AudioFormat audio_format, seekable); { - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; dc.SetReady(audio_format, seekable, duration); } @@ -283,7 +283,7 @@ DecoderBridge::GetCommand() noexcept void DecoderBridge::CommandFinished() noexcept { - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; assert(dc.command != DecoderCommand::NONE || initial_seek_running); assert(dc.command != DecoderCommand::SEEK || @@ -379,7 +379,7 @@ DecoderBridge::OpenUri(const char *uri) auto is = InputStream::Open(uri, mutex); is->SetHandler(&dc); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { if (dc.command == DecoderCommand::STOP) throw StopDecoder(); @@ -403,7 +403,7 @@ try { if (dest.empty()) return 0; - std::unique_lock lock(is.mutex); + std::unique_lock lock{is.mutex}; while (true) { if (CheckCancelRead()) diff --git a/src/decoder/Control.hxx b/src/decoder/Control.hxx index 481b8744b..dc076a79a 100644 --- a/src/decoder/Control.hxx +++ b/src/decoder/Control.hxx @@ -215,7 +215,7 @@ public: [[gnu::pure]] bool LockIsIdle() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return IsIdle(); } @@ -225,7 +225,7 @@ public: [[gnu::pure]] bool LockIsStarting() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return IsStarting(); } @@ -237,13 +237,13 @@ public: [[gnu::pure]] bool LockHasFailed() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return HasFailed(); } [[gnu::pure]] bool LockIsReplayGainEnabled() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return replay_gain_mode != ReplayGainMode::OFF; } @@ -274,7 +274,7 @@ public: * Like CheckRethrowError(), but locks and unlocks the object. */ void LockCheckRethrowError() const { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; CheckRethrowError(); } @@ -344,13 +344,13 @@ private: * object. */ void LockSynchronousCommand(DecoderCommand cmd) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; ClearError(); SynchronousCommandLocked(lock, cmd); } void LockAsynchronousCommand(DecoderCommand cmd) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; command = cmd; Signal(); } diff --git a/src/decoder/Thread.cxx b/src/decoder/Thread.cxx index c21dff06a..29d30c49f 100644 --- a/src/decoder/Thread.cxx +++ b/src/decoder/Thread.cxx @@ -272,7 +272,7 @@ TryUriDecode(DecoderBridge &bridge, const char *uri) if (!plugin.SupportsUri(uri)) return false; - std::unique_lock lock(bridge.dc.mutex); + std::unique_lock lock{bridge.dc.mutex}; bridge.Reset(); return DecoderUriDecode(plugin, bridge, uri); }); @@ -296,7 +296,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri) MaybeLoadReplayGain(bridge, *input_stream); - std::unique_lock lock(dc.mutex); + std::unique_lock lock{dc.mutex}; bool tried = false; return dc.command == DecoderCommand::STOP || @@ -326,10 +326,10 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, std::string_view suffix, DecoderControl &dc = bridge.dc; if (plugin.file_decode != nullptr) { - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; return decoder_file_decode(plugin, bridge, path_fs); } else if (plugin.stream_decode != nullptr) { - std::unique_lock lock(dc.mutex); + std::unique_lock lock{dc.mutex}; return decoder_stream_decode(plugin, bridge, input_stream, lock); } else @@ -354,7 +354,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, bridge.Reset(); DecoderControl &dc = bridge.dc; - const std::scoped_lock protect(dc.mutex); + const std::scoped_lock protect{dc.mutex}; return decoder_file_decode(plugin, bridge, path_fs); } @@ -545,7 +545,7 @@ DecoderControl::RunThread() noexcept { SetThreadName("decoder"); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; do { assert(state == DecoderState::STOP || diff --git a/src/input/AsyncInputStream.cxx b/src/input/AsyncInputStream.cxx index acdc9c956..86024c918 100644 --- a/src/input/AsyncInputStream.cxx +++ b/src/input/AsyncInputStream.cxx @@ -242,7 +242,7 @@ AsyncInputStream::AppendToBuffer(std::span src) noexcept void AsyncInputStream::DeferredResume() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; try { Resume(); @@ -255,7 +255,7 @@ AsyncInputStream::DeferredResume() noexcept void AsyncInputStream::DeferredSeek() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (seek_state != SeekState::SCHEDULED) return; diff --git a/src/input/BufferingInputStream.cxx b/src/input/BufferingInputStream.cxx index 5e901176b..d66448305 100644 --- a/src/input/BufferingInputStream.cxx +++ b/src/input/BufferingInputStream.cxx @@ -23,7 +23,7 @@ BufferingInputStream::BufferingInputStream(InputStreamPtr _input) BufferingInputStream::~BufferingInputStream() noexcept { { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; stop = true; wake_cond.notify_one(); } @@ -166,7 +166,7 @@ BufferingInputStream::RunThread() noexcept { SetThreadName("buffering"); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; try { RunThreadLocked(lock); diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx index f3b8b7d06..3b9fa6a47 100644 --- a/src/input/InputStream.cxx +++ b/src/input/InputStream.cxx @@ -61,14 +61,14 @@ InputStream::Seek(std::unique_lock &, [[maybe_unused]] offset_type new_of void InputStream::LockSeek(offset_type _offset) { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; Seek(lock, _offset); } void InputStream::LockSkip(offset_type _offset) { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; Skip(lock, _offset); } @@ -81,7 +81,7 @@ InputStream::ReadTag() noexcept std::unique_ptr InputStream::LockReadTag() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return ReadTag(); } @@ -96,7 +96,7 @@ InputStream::LockRead(std::span dest) { assert(!dest.empty()); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; return Read(lock, dest); } @@ -119,14 +119,14 @@ InputStream::LockReadFull(std::span dest) { assert(!dest.empty()); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; ReadFull(lock, dest); } bool InputStream::LockIsEOF() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return IsEOF(); } diff --git a/src/input/InputStream.hxx b/src/input/InputStream.hxx index b38cc67df..d35ceb9d9 100644 --- a/src/input/InputStream.hxx +++ b/src/input/InputStream.hxx @@ -289,7 +289,7 @@ public: } void LockRewind() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; Rewind(lock); } diff --git a/src/input/ThreadInputStream.cxx b/src/input/ThreadInputStream.cxx index 802849a8c..3f8ec3c63 100644 --- a/src/input/ThreadInputStream.cxx +++ b/src/input/ThreadInputStream.cxx @@ -30,7 +30,7 @@ ThreadInputStream::Stop() noexcept return; { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; close = true; wake_cond.notify_one(); } @@ -53,7 +53,7 @@ ThreadInputStream::ThreadFunc() noexcept { FmtThreadName("input:{}", plugin); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; try { Open(); diff --git a/src/input/cache/Item.cxx b/src/input/cache/Item.cxx index 2948675e9..bd2644db0 100644 --- a/src/input/cache/Item.cxx +++ b/src/input/cache/Item.cxx @@ -21,14 +21,14 @@ InputCacheItem::~InputCacheItem() noexcept void InputCacheItem::AddLease(InputCacheLease &lease) noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; leases.push_back(lease); } void InputCacheItem::RemoveLease(InputCacheLease &lease) noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; auto i = leases.iterator_to(lease); if (i == next_lease) ++next_lease; diff --git a/src/input/cache/Item.hxx b/src/input/cache/Item.hxx index a43d7eb22..6c7b8c39c 100644 --- a/src/input/cache/Item.hxx +++ b/src/input/cache/Item.hxx @@ -43,7 +43,7 @@ public: using BufferingInputStream::size; bool IsInUse() const noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; return !leases.empty(); } diff --git a/src/input/cache/Stream.cxx b/src/input/cache/Stream.cxx index 968b148fd..8ee6e6cf1 100644 --- a/src/input/cache/Stream.cxx +++ b/src/input/cache/Stream.cxx @@ -20,7 +20,7 @@ CacheInputStream::Check() const ScopeUnlock unlock(mutex); auto &i = GetCacheItem(); - const std::scoped_lock protect(i.mutex); + const std::scoped_lock protect{i.mutex}; i.Check(); } @@ -44,7 +44,7 @@ CacheInputStream::IsAvailable() const noexcept const ScopeUnlock unlock(mutex); auto &i = GetCacheItem(); - const std::scoped_lock protect(i.mutex); + const std::scoped_lock protect{i.mutex}; return i.IsAvailable(_offset); } @@ -60,7 +60,7 @@ CacheInputStream::Read(std::unique_lock &lock, { const ScopeUnlock unlock(mutex); - const std::scoped_lock protect(i.mutex); + const std::scoped_lock protect{i.mutex}; nbytes = i.Read(lock, _offset, dest); } @@ -75,6 +75,6 @@ CacheInputStream::OnInputCacheAvailable() noexcept auto &i = GetCacheItem(); const ScopeUnlock unlock(i.mutex); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; InvokeOnAvailable(); } diff --git a/src/input/plugins/AlsaInputPlugin.cxx b/src/input/plugins/AlsaInputPlugin.cxx index 6ed7da7a7..6a98a212e 100644 --- a/src/input/plugins/AlsaInputPlugin.cxx +++ b/src/input/plugins/AlsaInputPlugin.cxx @@ -222,7 +222,7 @@ AlsaInputStream::DispatchSockets() noexcept try { non_block.DispatchSockets(*this, capture_handle); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto w = PrepareWriteBuffer(); const snd_pcm_uframes_t w_frames = w.size() / frame_size; diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index 30e226aee..5f56d6d01 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -266,7 +266,7 @@ CurlInputStream::OnHeaders(unsigned status, FmtBuffer<40>("got HTTP status {}", status).c_str()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (IsSeekPending()) { /* don't update metadata while seeking */ @@ -329,7 +329,7 @@ CurlInputStream::OnData(std::span data) { assert(!data.empty()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (IsSeekPending()) SeekDone(); @@ -345,7 +345,7 @@ CurlInputStream::OnData(std::span data) void CurlInputStream::OnEnd() { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; InvokeOnAvailable(); AsyncInputStream::SetClosed(); @@ -354,7 +354,7 @@ CurlInputStream::OnEnd() void CurlInputStream::OnError(std::exception_ptr e) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; postponed_exception = std::move(e); if (IsSeekPending()) diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx index 7306d826e..2fccc4d14 100644 --- a/src/input/plugins/NfsInputPlugin.cxx +++ b/src/input/plugins/NfsInputPlugin.cxx @@ -138,7 +138,7 @@ NfsInputStream::DoSeek(offset_type new_offset) void NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (reconnecting) { /* reconnect has succeeded */ @@ -158,7 +158,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept void NfsInputStream::OnNfsFileRead(std::span src) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(!IsBufferFull()); assert(IsBufferFull() == (GetBufferSpace() == 0)); @@ -172,7 +172,7 @@ NfsInputStream::OnNfsFileRead(std::span src) noexcept void NfsInputStream::OnNfsFileError(std::exception_ptr &&e) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (IsPaused()) { /* while we're paused, don't report this error to the diff --git a/src/input/plugins/QobuzClient.cxx b/src/input/plugins/QobuzClient.cxx index 9d93e4c13..6418d43aa 100644 --- a/src/input/plugins/QobuzClient.cxx +++ b/src/input/plugins/QobuzClient.cxx @@ -71,7 +71,7 @@ QobuzClient::StartLogin() void QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(!h.is_linked()); const bool was_empty = handlers.empty(); @@ -98,7 +98,7 @@ QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept QobuzSession QobuzClient::GetSession() const { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (error) std::rethrow_exception(error); @@ -113,7 +113,7 @@ void QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept { { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; session = std::move(_session); login_request.reset(); } @@ -125,7 +125,7 @@ void QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept { { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; error = std::move(_error); login_request.reset(); } @@ -136,7 +136,7 @@ QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept void QobuzClient::InvokeHandlers() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; while (!handlers.empty()) { auto &h = handlers.front(); handlers.pop_front(); diff --git a/src/input/plugins/QobuzClient.hxx b/src/input/plugins/QobuzClient.hxx index 2b37fa658..3e702a6a6 100644 --- a/src/input/plugins/QobuzClient.hxx +++ b/src/input/plugins/QobuzClient.hxx @@ -67,7 +67,7 @@ public: void AddLoginHandler(QobuzSessionHandler &h) noexcept; void RemoveLoginHandler(QobuzSessionHandler &h) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (h.is_linked()) h.unlink(); } diff --git a/src/input/plugins/QobuzInputPlugin.cxx b/src/input/plugins/QobuzInputPlugin.cxx index 12be48c87..ce3e739bf 100644 --- a/src/input/plugins/QobuzInputPlugin.cxx +++ b/src/input/plugins/QobuzInputPlugin.cxx @@ -68,7 +68,7 @@ private: void QobuzInputStream::OnQobuzSession() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; try { const auto session = qobuz_client->GetSession(); @@ -87,7 +87,7 @@ QobuzInputStream::OnQobuzSession() noexcept void QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; track_request.reset(); try { @@ -101,7 +101,7 @@ QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept void QobuzInputStream::OnQobuzTrackError(std::exception_ptr e) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; track_request.reset(); Failed(e); diff --git a/src/input/plugins/UringInputPlugin.cxx b/src/input/plugins/UringInputPlugin.cxx index 9e0ecdbad..bea7c523b 100644 --- a/src/input/plugins/UringInputPlugin.cxx +++ b/src/input/plugins/UringInputPlugin.cxx @@ -133,7 +133,7 @@ UringInputStream::OnRead(std::unique_ptr data, { read_operation.reset(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (nbytes == 0) { postponed_exception = std::make_exception_ptr(std::runtime_error("Premature end of file")); @@ -154,7 +154,7 @@ UringInputStream::OnReadError(int error) noexcept { read_operation.reset(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; postponed_exception = std::make_exception_ptr(MakeErrno(error, "Read failed")); InvokeOnAvailable(); diff --git a/src/lib/icu/Converter.cxx b/src/lib/icu/Converter.cxx index b8264e369..1c058c626 100644 --- a/src/lib/icu/Converter.cxx +++ b/src/lib/icu/Converter.cxx @@ -92,7 +92,7 @@ AllocatedString IcuConverter::ToUTF8(std::string_view s) const { #ifdef HAVE_ICU - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; ucnv_resetToUnicode(converter); @@ -119,7 +119,7 @@ AllocatedString IcuConverter::FromUTF8(std::string_view s) const { #ifdef HAVE_ICU - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; const auto u = UCharFromUTF8(s); diff --git a/src/lib/nfs/Blocking.hxx b/src/lib/nfs/Blocking.hxx index c017cb258..553c9a88a 100644 --- a/src/lib/nfs/Blocking.hxx +++ b/src/lib/nfs/Blocking.hxx @@ -43,7 +43,7 @@ public: private: bool LockWaitFinished() noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; return cond.wait_for(lock, timeout, [this]{ return finished; }); } @@ -52,7 +52,7 @@ private: * thread. */ void LockSetFinished() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; finished = true; cond.notify_one(); } diff --git a/src/lib/smbclient/Context.cxx b/src/lib/smbclient/Context.cxx index 16ecf3e88..f938bca98 100644 --- a/src/lib/smbclient/Context.cxx +++ b/src/lib/smbclient/Context.cxx @@ -29,7 +29,7 @@ SmbclientContext::New() SMBCCTX *ctx; { - const std::scoped_lock protect(global_mutex); + const std::scoped_lock protect{global_mutex}; ctx = smbc_new_context(); } diff --git a/src/lib/smbclient/Context.hxx b/src/lib/smbclient/Context.hxx index 7694918a0..b50ffa4bc 100644 --- a/src/lib/smbclient/Context.hxx +++ b/src/lib/smbclient/Context.hxx @@ -32,7 +32,7 @@ public: ~SmbclientContext() noexcept { if (ctx != nullptr) { - const std::scoped_lock protect(global_mutex); + const std::scoped_lock protect{global_mutex}; smbc_free_context(ctx, 1); } } diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx index 848c132b7..2ce45f5a0 100644 --- a/src/lib/upnp/ClientInit.cxx +++ b/src/lib/upnp/ClientInit.cxx @@ -45,7 +45,7 @@ UpnpClientGlobalInit(const char* iface) UpnpGlobalInit(iface); try { - const std::scoped_lock protect(upnp_client_init_mutex); + const std::scoped_lock protect{upnp_client_init_mutex}; if (upnp_client_ref == 0) DoInit(); } catch (...) { @@ -61,7 +61,7 @@ void UpnpClientGlobalFinish() noexcept { { - const std::scoped_lock protect(upnp_client_init_mutex); + const std::scoped_lock protect{upnp_client_init_mutex}; assert(upnp_client_ref > 0); if (--upnp_client_ref == 0) diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 804efd641..f0fc83481 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -88,14 +88,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))), request(*parent.curl, url.c_str(), *this) { - const std::scoped_lock protect(parent.mutex); + const std::scoped_lock protect{parent.mutex}; parent.downloaders.push_back(*this); } void UPnPDeviceDirectory::Downloader::Destroy() noexcept { - const std::scoped_lock protect(parent.mutex); + const std::scoped_lock protect{parent.mutex}; unlink(); delete this; } @@ -189,7 +189,7 @@ AnnounceLostUPnP(UPnPDiscoveryListener &listener, const UPnPDevice &device) noex inline void UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; const auto i = directories.insert_or_assign(std::move(id), std::move(d)).first; @@ -200,7 +200,7 @@ UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d) n inline void UPnPDeviceDirectory::LockRemove(const std::string_view id) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (auto i = directories.find(id); i != directories.end()) { if (listener != nullptr) @@ -297,7 +297,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop, UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept { BlockingCall(GetEventLoop(), [this]() { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; downloaders.clear_and_dispose(DeleteDisposer()); }); } @@ -337,7 +337,7 @@ UPnPDeviceDirectory::Search() std::vector UPnPDeviceDirectory::GetDirectories() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; ExpireDevices(); @@ -356,7 +356,7 @@ UPnPDeviceDirectory::GetDirectories() noexcept ContentDirectoryService UPnPDeviceDirectory::GetServer(std::string_view friendly_name) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; ExpireDevices(); diff --git a/src/lib/upnp/Init.cxx b/src/lib/upnp/Init.cxx index 8923dccc3..d1c209dbc 100644 --- a/src/lib/upnp/Init.cxx +++ b/src/lib/upnp/Init.cxx @@ -33,7 +33,7 @@ DoInit(const char* iface) void UpnpGlobalInit(const char* iface) { - const std::scoped_lock protect(upnp_init_mutex); + const std::scoped_lock protect{upnp_init_mutex}; if (upnp_ref == 0) DoInit(iface); @@ -44,7 +44,7 @@ UpnpGlobalInit(const char* iface) void UpnpGlobalFinish() noexcept { - const std::scoped_lock protect(upnp_init_mutex); + const std::scoped_lock protect{upnp_init_mutex}; assert(upnp_ref > 0); diff --git a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx index e665965ca..9cb7a3499 100644 --- a/src/neighbor/plugins/SmbclientNeighborPlugin.cxx +++ b/src/neighbor/plugins/SmbclientNeighborPlugin.cxx @@ -83,7 +83,7 @@ void SmbclientNeighborExplorer::Close() noexcept { { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; quit = true; cond.notify_one(); } @@ -94,7 +94,7 @@ SmbclientNeighborExplorer::Close() noexcept NeighborExplorer::List SmbclientNeighborExplorer::GetList() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return list; } @@ -224,7 +224,7 @@ SmbclientNeighborExplorer::ThreadFunc() noexcept { SetThreadName("smbclient"); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (!quit) { Run(); diff --git a/src/neighbor/plugins/UdisksNeighborPlugin.cxx b/src/neighbor/plugins/UdisksNeighborPlugin.cxx index 4a59e5941..3eac703c6 100644 --- a/src/neighbor/plugins/UdisksNeighborPlugin.cxx +++ b/src/neighbor/plugins/UdisksNeighborPlugin.cxx @@ -159,7 +159,7 @@ UdisksNeighborExplorer::Close() noexcept NeighborExplorer::List UdisksNeighborExplorer::GetList() const noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; NeighborExplorer::List result; @@ -176,7 +176,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept const NeighborInfo info = ToNeighborInfo(o); { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto i = by_uri.emplace(o.GetUri(), info); if (!i.second) i.first->second = info; @@ -191,7 +191,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept void UdisksNeighborExplorer::Remove(const std::string &path) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; auto i = by_path.find(path); if (i == by_path.end()) diff --git a/src/output/Control.cxx b/src/output/Control.cxx index a034df91d..0464cd9f0 100644 --- a/src/output/Control.cxx +++ b/src/output/Control.cxx @@ -54,7 +54,7 @@ AudioOutputControl::Steal() noexcept /* close and disable the output */ { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (really_enabled && output->SupportsEnableDisable()) CommandWait(lock, Command::DISABLE); @@ -65,7 +65,7 @@ AudioOutputControl::Steal() noexcept StopThread(); /* now we can finally remove it */ - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return std::exchange(output, nullptr); } @@ -77,7 +77,7 @@ AudioOutputControl::ReplaceDummy(std::unique_ptr new_output assert(new_output); { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; output = std::move(new_output); enabled = _enabled; } @@ -126,7 +126,7 @@ AudioOutputControl::SetAttribute(std::string &&attribute_name, bool AudioOutputControl::LockSetEnabled(bool new_value) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (new_value == enabled) return false; @@ -138,7 +138,7 @@ AudioOutputControl::LockSetEnabled(bool new_value) noexcept bool AudioOutputControl::LockToggleEnabled() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return enabled = !enabled; } @@ -168,7 +168,7 @@ AudioOutputControl::CommandWait(std::unique_lock &lock, void AudioOutputControl::LockCommandWait(Command cmd) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; CommandWait(lock, cmd); } @@ -300,7 +300,7 @@ AudioOutputControl::LockUpdate(const AudioFormat audio_format, const MusicPipe &mp, bool force) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (enabled && really_enabled) { if (force || !fail_timer.IsDefined() || @@ -325,14 +325,14 @@ AudioOutputControl::IsChunkConsumed(const MusicChunk &chunk) const noexcept bool AudioOutputControl::LockIsChunkConsumed(const MusicChunk &chunk) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return IsChunkConsumed(chunk); } void AudioOutputControl::LockPlay() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(allow_play); @@ -354,7 +354,7 @@ AudioOutputControl::LockPauseAsync() noexcept if (output) output->Interrupt(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(allow_play); if (IsOpen()) @@ -364,7 +364,7 @@ AudioOutputControl::LockPauseAsync() noexcept void AudioOutputControl::LockDrainAsync() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(allow_play); if (IsOpen()) @@ -377,7 +377,7 @@ AudioOutputControl::LockCancelAsync() noexcept if (output) output->Interrupt(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (IsOpen()) { allow_play = false; @@ -388,7 +388,7 @@ AudioOutputControl::LockCancelAsync() noexcept void AudioOutputControl::LockAllowPlay() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; allow_play = true; if (IsOpen()) @@ -410,7 +410,7 @@ AudioOutputControl::LockRelease() noexcept Mixer::LockAutoClose()) */ output->mixer->LockAutoClose(); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; assert(!open || !fail_timer.IsDefined()); assert(allow_play); @@ -429,7 +429,7 @@ AudioOutputControl::LockCloseWait() noexcept if (output) output->Interrupt(); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; CloseWait(lock); } @@ -440,7 +440,7 @@ AudioOutputControl::BeginDestroy() noexcept if (output) output->Interrupt(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (!killed) { killed = true; CommandAsync(Command::KILL); diff --git a/src/output/Control.hxx b/src/output/Control.hxx index 1a4747fac..5636f2a3c 100644 --- a/src/output/Control.hxx +++ b/src/output/Control.hxx @@ -355,7 +355,7 @@ public: void WaitForCommand(std::unique_lock &lock) noexcept; void LockWaitForCommand() noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; WaitForCommand(lock); } @@ -407,7 +407,7 @@ public: void EnableDisableAsync(); void LockEnableDisableAsync() { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; EnableDisableAsync(); } @@ -482,7 +482,7 @@ public: * Locking wrapper for ClearTailChunk(). */ void LockClearTailChunk(const MusicChunk &chunk) noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; ClearTailChunk(chunk); } diff --git a/src/output/MultipleOutputs.cxx b/src/output/MultipleOutputs.cxx index 18464d3a6..26e2b2e93 100644 --- a/src/output/MultipleOutputs.cxx +++ b/src/output/MultipleOutputs.cxx @@ -213,7 +213,7 @@ MultipleOutputs::Open(const AudioFormat audio_format) std::exception_ptr first_error; for (const auto &ao : outputs) { - const std::scoped_lock lock(ao->mutex); + const std::scoped_lock lock{ao->mutex}; /* can't play on this device even if it's enabled */ if (ao->AlwaysOff()) diff --git a/src/output/State.cxx b/src/output/State.cxx index 89191c571..aa6e54e01 100644 --- a/src/output/State.cxx +++ b/src/output/State.cxx @@ -27,7 +27,7 @@ audio_output_state_save(BufferedOutputStream &os, { for (unsigned i = 0, n = outputs.Size(); i != n; ++i) { const auto &ao = outputs.Get(i); - const std::scoped_lock lock(ao.mutex); + const std::scoped_lock lock{ao.mutex}; os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"), (unsigned)ao.IsEnabled(), ao.GetName()); diff --git a/src/output/Thread.cxx b/src/output/Thread.cxx index 25611435d..b8f5e38e3 100644 --- a/src/output/Thread.cxx +++ b/src/output/Thread.cxx @@ -417,7 +417,7 @@ AudioOutputControl::Task() noexcept SetThreadTimerSlack(std::chrono::microseconds(100)); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { switch (command) { diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index b857d1476..9968cb2c8 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -294,13 +294,13 @@ private: [[gnu::pure]] bool LockIsActive() const noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; return active; } [[gnu::pure]] bool LockIsActiveAndNotWaiting() const noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; return active && !waiting; } @@ -366,7 +366,7 @@ private: void LockCaughtError() noexcept { period_buffer.Clear(); - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; error = std::current_exception(); active = false; waiting = false; @@ -381,7 +381,7 @@ private: */ void OnSilenceTimer() noexcept { { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; assert(active); waiting = false; } @@ -447,7 +447,7 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block) std::map> AlsaOutput::GetAttributes() const noexcept { - const std::scoped_lock lock(attributes_mutex); + const std::scoped_lock lock{attributes_mutex}; return { {"allowed_formats", Alsa::ToString(allowed_formats)}, @@ -461,11 +461,11 @@ void AlsaOutput::SetAttribute(std::string &&name, std::string &&value) { if (name == "allowed_formats") { - const std::scoped_lock lock(attributes_mutex); + const std::scoped_lock lock{attributes_mutex}; allowed_formats = Alsa::AllowedFormat::ParseList(value); #ifdef ENABLE_DSD } else if (name == "dop") { - const std::scoped_lock lock(attributes_mutex); + const std::scoped_lock lock{attributes_mutex}; if (value == "0") dop_setting = false; else if (value == "1") @@ -773,7 +773,7 @@ AlsaOutput::Open(AudioFormat &audio_format) #endif { - const std::scoped_lock lock(attributes_mutex); + const std::scoped_lock lock{attributes_mutex}; #ifdef ENABLE_DSD dop = dop_setting; #endif @@ -877,7 +877,7 @@ AlsaOutput::Open(AudioFormat &audio_format) void AlsaOutput::Interrupt() noexcept { - std::unique_lock lock(mutex); + std::scoped_lock lock{mutex}; /* the "interrupted" flag will prevent LockWaitWriteAvailable() from actually waiting, and will @@ -951,7 +951,7 @@ AlsaOutput::CopyRingToPeriodBuffer() noexcept period_buffer.AppendBytes(nbytes); - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; /* notify the OutputThread that there is now room in ring_buffer */ cond.notify_one(); @@ -1069,7 +1069,7 @@ AlsaOutput::DrainInternal() void AlsaOutput::Drain() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (error) std::rethrow_exception(error); @@ -1110,7 +1110,7 @@ void AlsaOutput::Cancel() noexcept { { - std::unique_lock lock(mutex); + std::lock_guard lock{mutex}; interrupted = false; } @@ -1128,7 +1128,7 @@ AlsaOutput::Cancel() noexcept #ifdef ENABLE_DSD if (stop_dsd_silence && use_dsd) { /* play some DSD silence instead of snd_pcm_drop() */ - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; in_stop_dsd_silence = true; drain = true; cond.wait(lock, [this]{ return !drain || !active; }); @@ -1144,7 +1144,7 @@ AlsaOutput::Cancel() noexcept bool AlsaOutput::Pause() noexcept { - std::unique_lock lock(mutex); + std::lock_guard lock{mutex}; interrupted = false; /* not implemented - this override exists only to reset the @@ -1174,7 +1174,7 @@ AlsaOutput::LockWaitWriteAvailable() const size_t out_block_size = pcm_export->GetOutputBlockSize(); const size_t min_available = 2 * out_block_size; - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { if (error) @@ -1265,7 +1265,7 @@ try { } { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; assert(active); @@ -1305,7 +1305,7 @@ try { smaller than the ALSA-PCM buffer */ { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; waiting = true; cond.notify_one(); } diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx index 8f33c71ee..c393267d4 100644 --- a/src/output/plugins/JackOutputPlugin.cxx +++ b/src/output/plugins/JackOutputPlugin.cxx @@ -102,7 +102,7 @@ private: void Disconnect() noexcept; void Shutdown(const char *reason) noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; error = std::make_exception_ptr(FmtRuntimeError("JACK connection shutdown: {}", reason)); } @@ -166,7 +166,7 @@ public: private: bool LockWasShutdown() const noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; return !!error; } }; @@ -618,7 +618,7 @@ JackOutput::Open(AudioFormat &new_audio_format) void JackOutput::Interrupt() noexcept { - const std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; /* the "interrupted" flag will prevent Play() from waiting, and will instead throw AudioOutputInterrupted */ @@ -680,7 +680,7 @@ JackOutput::Play(std::span _src) while (true) { { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; if (error) std::rethrow_exception(error); @@ -702,7 +702,7 @@ JackOutput::Play(std::span _src) void JackOutput::Cancel() noexcept { - const std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; interrupted = false; } @@ -710,7 +710,7 @@ inline bool JackOutput::Pause() { { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; interrupted = false; if (error) std::rethrow_exception(error); diff --git a/src/output/plugins/httpd/HttpdClient.cxx b/src/output/plugins/httpd/HttpdClient.cxx index 40775157b..b097cd38f 100644 --- a/src/output/plugins/httpd/HttpdClient.cxx +++ b/src/output/plugins/httpd/HttpdClient.cxx @@ -34,7 +34,7 @@ HttpdClient::Close() noexcept void HttpdClient::LockClose() noexcept { - const std::scoped_lock protect(httpd.mutex); + const std::scoped_lock protect{httpd.mutex}; Close(); } @@ -224,7 +224,7 @@ HttpdClient::GetBytesTillMetaData() const noexcept inline bool HttpdClient::TryWrite() noexcept { - const std::scoped_lock protect(httpd.mutex); + const std::scoped_lock protect{httpd.mutex}; assert(state == State::RESPONSE); diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index 476508546..4b41f87e0 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -182,7 +182,7 @@ public: */ [[gnu::pure]] bool LockHasClients() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return HasClients(); } diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 5683f5e18..4409987ab 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -96,7 +96,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept /* this method runs in the IOThread; it broadcasts pages from our own queue to all clients */ - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; while (!pages.empty()) { PagePtr page = std::move(pages.front()); @@ -118,7 +118,7 @@ HttpdOutput::OnAccept(UniqueSocketDescriptor fd, /* the listener socket has become readable - a client has connected */ - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; /* can we allow additional client */ if (open && (clients_max == 0 || clients.size() < clients_max)) @@ -197,7 +197,7 @@ HttpdOutput::Open(AudioFormat &audio_format) assert(!open); assert(clients.empty()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; OpenEncoder(audio_format); @@ -219,7 +219,7 @@ HttpdOutput::Close() noexcept BlockingCall(GetEventLoop(), [this](){ defer_broadcast.Cancel(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; open = false; clients.clear_and_dispose(DeleteDisposer()); }); @@ -272,7 +272,7 @@ HttpdOutput::BroadcastPage(PagePtr page) noexcept assert(page != nullptr); { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; pages.emplace(std::move(page)); } @@ -284,7 +284,7 @@ HttpdOutput::BroadcastFromEncoder() noexcept { /* synchronize with the IOThread */ { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; cond.wait(lock, [this]{ return pages.empty(); }); } @@ -292,7 +292,7 @@ HttpdOutput::BroadcastFromEncoder() noexcept PagePtr page; while ((page = ReadPage()) != nullptr) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; pages.emplace(std::move(page)); empty = false; } @@ -384,7 +384,7 @@ HttpdOutput::SendTag(const Tag &tag) metadata = icy_server_metadata_page(tag, &types[0]); if (metadata != nullptr) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; for (auto &client : clients) client.PushMetaData(metadata); } @@ -394,7 +394,7 @@ HttpdOutput::SendTag(const Tag &tag) inline void HttpdOutput::CancelAllClients() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; while (!pages.empty()) { PagePtr page = std::move(pages.front()); diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index e04cf46e8..2db8e0426 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -330,7 +330,7 @@ SlesOutput::Play(std::span src) pause = false; } - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; assert(filled < BUFFER_SIZE); @@ -360,7 +360,7 @@ SlesOutput::Play(std::span src) void SlesOutput::Drain() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; assert(filled < BUFFER_SIZE); @@ -382,7 +382,7 @@ SlesOutput::Cancel() noexcept LogWarning(sles_domain, "AndroidSimpleBufferQueue.Clear() failed"); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; n_queued = 0; filled = 0; } @@ -407,7 +407,7 @@ SlesOutput::Pause() inline void SlesOutput::PlayedCallback() { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; assert(n_queued > 0); --n_queued; cond.notify_one(); diff --git a/src/output/plugins/snapcast/Client.cxx b/src/output/plugins/snapcast/Client.cxx index cc3d62a5d..53529840b 100644 --- a/src/output/plugins/snapcast/Client.cxx +++ b/src/output/plugins/snapcast/Client.cxx @@ -40,7 +40,7 @@ SnapcastClient::Close() noexcept void SnapcastClient::LockClose() noexcept { - const std::scoped_lock protect(output.mutex); + const std::scoped_lock protect{output.mutex}; Close(); } @@ -57,7 +57,7 @@ SnapcastClient::Push(SnapcastChunkPtr chunk) noexcept SnapcastChunkPtr SnapcastClient::LockPopQueue() noexcept { - const std::scoped_lock protect(output.mutex); + const std::scoped_lock protect{output.mutex}; if (chunks.empty()) return nullptr; diff --git a/src/output/plugins/snapcast/Internal.hxx b/src/output/plugins/snapcast/Internal.hxx index 3d59042cc..75c6ed156 100644 --- a/src/output/plugins/snapcast/Internal.hxx +++ b/src/output/plugins/snapcast/Internal.hxx @@ -118,7 +118,7 @@ public: */ [[gnu::pure]] bool LockHasClients() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return HasClients(); } diff --git a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx index ecb52d77e..ff0a549fa 100644 --- a/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx +++ b/src/output/plugins/snapcast/SnapcastOutputPlugin.cxx @@ -100,7 +100,7 @@ SnapcastOutput::OnAccept(UniqueSocketDescriptor fd, /* the listener socket has become readable - a client has connected */ - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; /* can we allow additional client */ if (open) @@ -130,7 +130,7 @@ SnapcastOutput::Open(AudioFormat &audio_format) assert(!open); assert(clients.empty()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; OpenEncoder(audio_format); @@ -152,7 +152,7 @@ SnapcastOutput::Close() noexcept BlockingCall(GetEventLoop(), [this](){ inject_event.Cancel(); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; open = false; clients.clear_and_dispose(DeleteDisposer{}); }); @@ -166,7 +166,7 @@ SnapcastOutput::Close() noexcept void SnapcastOutput::OnInject() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; while (!chunks.empty()) { const auto chunk = std::move(chunks.front()); @@ -272,7 +272,7 @@ SnapcastOutput::SendTag(const Tag &tag) const auto payload = std::as_bytes(std::span{json}); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; // TODO: enqueue StreamTags, don't send directly for (auto &client : clients) client.SendStreamTags(payload); @@ -320,7 +320,7 @@ SnapcastOutput::Play(std::span src) unflushed_input = 0; - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (chunks.empty()) inject_event.Schedule(); @@ -350,14 +350,14 @@ SnapcastOutput::IsDrained() const noexcept void SnapcastOutput::Drain() { - std::unique_lock protect(mutex); + std::unique_lock protect{mutex}; drain_cond.wait(protect, [this]{ return IsDrained(); }); } void SnapcastOutput::Cancel() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; ClearQueue(chunks); diff --git a/src/player/Control.cxx b/src/player/Control.cxx index ed52558f9..1749c3fd8 100644 --- a/src/player/Control.cxx +++ b/src/player/Control.cxx @@ -47,7 +47,7 @@ PlayerControl::Play(std::unique_ptr song) assert(song != nullptr); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; SeekLocked(lock, std::move(song), SongTime::zero()); if (state == PlayerState::PAUSE) @@ -110,7 +110,7 @@ PlayerControl::PauseLocked(std::unique_lock &lock) noexcept void PlayerControl::LockPause() noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; PauseLocked(lock); } @@ -120,7 +120,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept if (!thread.IsDefined()) return; - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; switch (state) { case PlayerState::STOP: @@ -141,7 +141,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept void PlayerControl::LockSetBorderPause(bool _border_pause) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; border_pause = _border_pause; } @@ -150,7 +150,7 @@ PlayerControl::LockGetStatus() noexcept { PlayerStatus status; - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (!occupied && thread.IsDefined()) SynchronousCommand(lock, PlayerCommand::REFRESH); @@ -182,14 +182,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept void PlayerControl::LockClearError() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; ClearError(); } void PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; tagged_song.reset(); tagged_song = std::make_unique(song); } @@ -209,7 +209,7 @@ PlayerControl::ReadTaggedSong() noexcept std::unique_ptr PlayerControl::LockReadTaggedSong() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return ReadTaggedSong(); } @@ -219,7 +219,7 @@ PlayerControl::LockEnqueueSong(std::unique_ptr song) noexcept assert(thread.IsDefined()); assert(song != nullptr); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; EnqueueSongLocked(lock, std::move(song)); } @@ -278,7 +278,7 @@ PlayerControl::LockSeek(std::unique_ptr song, SongTime t) assert(song != nullptr); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; SeekLocked(lock, std::move(song), t); } diff --git a/src/player/Control.hxx b/src/player/Control.hxx index 5c5418bb6..623fb4335 100644 --- a/src/player/Control.hxx +++ b/src/player/Control.hxx @@ -224,7 +224,7 @@ public: * Like CheckRethrowError(), but locks and unlocks the object. */ void LockCheckRethrowError() const { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; CheckRethrowError(); } @@ -293,7 +293,7 @@ public: } void LockSetReplayGainMode(ReplayGainMode _mode) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; replay_gain_mode = _mode; } @@ -316,7 +316,7 @@ public: [[gnu::pure]] SyncInfo LockGetSyncInfo() const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return {state, next_song != nullptr}; } @@ -338,7 +338,7 @@ private: * this function. */ void LockSignal() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; Signal(); } @@ -391,7 +391,7 @@ private: } void LockCommandFinished() noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; CommandFinished(); } @@ -409,7 +409,7 @@ private: unsigned threshold) noexcept; bool LockWaitOutputConsumed(unsigned threshold) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; return WaitOutputConsumed(lock, threshold); } @@ -448,7 +448,7 @@ private: * object. */ void LockSynchronousCommand(PlayerCommand cmd) noexcept { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; SynchronousCommand(lock, cmd); } @@ -486,7 +486,7 @@ private: } void LockSetOutputError(std::exception_ptr &&_error) noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; SetOutputError(std::move(_error)); } diff --git a/src/player/Thread.cxx b/src/player/Thread.cxx index 4449374d6..0be11354e 100644 --- a/src/player/Thread.cxx +++ b/src/player/Thread.cxx @@ -923,7 +923,7 @@ PlayerControl::PlayChunk(DetachedSong &song, MusicChunkPtr chunk, return; { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; bit_rate = chunk->bit_rate; } @@ -997,7 +997,7 @@ Player::PlayNextChunk() noexcept } else { /* there are not enough decoded chunks yet */ - std::unique_lock lock(pc.mutex); + std::unique_lock lock{pc.mutex}; if (dc.IsIdle()) { /* the decoder isn't running, abort @@ -1045,7 +1045,7 @@ Player::PlayNextChunk() noexcept return false; } - const std::scoped_lock lock(pc.mutex); + const std::scoped_lock lock{pc.mutex}; /* this formula should prevent that the decoder gets woken up with each chunk; it is more efficient to make it decode a @@ -1096,7 +1096,7 @@ Player::Run() noexcept { pipe = std::make_shared(); - std::unique_lock lock(pc.mutex); + std::unique_lock lock{pc.mutex}; StartDecoder(lock, pipe, true); ActivateDecoder(); @@ -1248,7 +1248,7 @@ try { MusicBuffer buffer{config.buffer_chunks}; - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { switch (command) { diff --git a/src/storage/CompositeStorage.cxx b/src/storage/CompositeStorage.cxx index 88ccd1bc7..59f96f653 100644 --- a/src/storage/CompositeStorage.cxx +++ b/src/storage/CompositeStorage.cxx @@ -179,7 +179,7 @@ CompositeStorage::~CompositeStorage() = default; Storage * CompositeStorage::GetMount(std::string_view uri) noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto result = FindStorage(uri); if (!result.uri.empty()) @@ -192,7 +192,7 @@ CompositeStorage::GetMount(std::string_view uri) noexcept void CompositeStorage::Mount(const char *uri, std::unique_ptr storage) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; Directory &directory = root.Make(uri); assert(!directory.storage); @@ -202,7 +202,7 @@ CompositeStorage::Mount(const char *uri, std::unique_ptr storage) bool CompositeStorage::Unmount(const char *uri) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return root.Unmount(uri); } @@ -231,7 +231,7 @@ CompositeStorage::FindStorage(std::string_view uri) const noexcept StorageFileInfo CompositeStorage::GetInfo(std::string_view uri, bool follow) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; std::exception_ptr error; @@ -257,7 +257,7 @@ CompositeStorage::GetInfo(std::string_view uri, bool follow) std::unique_ptr CompositeStorage::OpenDirectory(std::string_view uri) { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto f = FindStorage(uri); const Directory *directory = f.directory->Find(f.uri); @@ -284,7 +284,7 @@ CompositeStorage::OpenDirectory(std::string_view uri) std::string CompositeStorage::MapUTF8(std::string_view uri) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto f = FindStorage(uri); if (f.directory->storage == nullptr) @@ -296,7 +296,7 @@ CompositeStorage::MapUTF8(std::string_view uri) const noexcept AllocatedPath CompositeStorage::MapFS(std::string_view uri) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; auto f = FindStorage(uri); if (f.directory->storage == nullptr) @@ -308,7 +308,7 @@ CompositeStorage::MapFS(std::string_view uri) const noexcept std::string_view CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (root.storage != nullptr) { auto result = root.storage->MapToRelativeUTF8(uri); @@ -325,7 +325,7 @@ CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept InputStreamPtr CompositeStorage::OpenFile(std::string_view uri_utf8, Mutex &_mutex) { - const std::lock_guard lock(mutex); + const std::lock_guard lock{mutex}; auto f = FindStorage(uri_utf8); if (f.directory->storage == nullptr) diff --git a/src/storage/CompositeStorage.hxx b/src/storage/CompositeStorage.hxx index 623e50417..ff47926ee 100644 --- a/src/storage/CompositeStorage.hxx +++ b/src/storage/CompositeStorage.hxx @@ -99,7 +99,7 @@ public: */ template void VisitMounts(T t) const { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; std::string uri; VisitMounts(uri, root, t); } @@ -109,7 +109,7 @@ public: */ [[gnu::pure]] [[gnu::nonnull]] bool IsMounted(const char *storage_uri) const noexcept { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; return IsMounted(root, storage_uri); } diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index bac92b513..cbe909b77 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -109,7 +109,7 @@ public: } void Wait() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; cond.wait(lock, [this]{ return done; }); if (postponed_error) @@ -130,7 +130,7 @@ protected: } void LockSetDone() { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; SetDone(); } @@ -148,7 +148,7 @@ private: /* virtual methods from CurlResponseHandler */ void OnError(std::exception_ptr e) noexcept final { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; postponed_error = std::move(e); SetDone(); } diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx index 5824f487b..8d96bbbd9 100644 --- a/src/storage/plugins/NfsStorage.cxx +++ b/src/storage/plugins/NfsStorage.cxx @@ -140,7 +140,7 @@ private: void SetState(State _state) noexcept { assert(GetEventLoop().IsInside()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; state = _state; cond.notify_all(); } @@ -148,7 +148,7 @@ private: void SetState(State _state, std::exception_ptr &&e) noexcept { assert(GetEventLoop().IsInside()); - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; state = _state; last_exception = std::move(e); cond.notify_all(); @@ -172,7 +172,7 @@ private: } void WaitConnected() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; while (true) { switch (state) { diff --git a/src/storage/plugins/SmbclientStorage.cxx b/src/storage/plugins/SmbclientStorage.cxx index 31b3b0bb0..c5c7f410e 100644 --- a/src/storage/plugins/SmbclientStorage.cxx +++ b/src/storage/plugins/SmbclientStorage.cxx @@ -89,7 +89,7 @@ GetInfo(SmbclientContext &ctx, Mutex &mutex, const char *path) struct stat st; { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; if (ctx.Stat(path, st) != 0) throw MakeErrno("Failed to access file"); } @@ -131,7 +131,7 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8) SMBCFILE *handle; { - const std::scoped_lock protect(mutex); + const std::scoped_lock protect{mutex}; handle = ctx.OpenDirectory(mapped.c_str()); } @@ -152,14 +152,14 @@ SkipNameFS(PathTraitsFS::const_pointer name) noexcept SmbclientDirectoryReader::~SmbclientDirectoryReader() { - const std::scoped_lock lock(storage.mutex); + const std::scoped_lock lock{storage.mutex}; storage.ctx.CloseDirectory(handle); } const char * SmbclientDirectoryReader::Read() noexcept { - const std::scoped_lock protect(storage.mutex); + const std::scoped_lock protect{storage.mutex}; while (auto e = storage.ctx.ReadDirectory(handle)) { name = e->name; diff --git a/src/storage/plugins/UdisksStorage.cxx b/src/storage/plugins/UdisksStorage.cxx index d7c4013f5..63d28cbb6 100644 --- a/src/storage/plugins/UdisksStorage.cxx +++ b/src/storage/plugins/UdisksStorage.cxx @@ -151,7 +151,7 @@ UdisksStorage::SetMountPoint(Path mount_point) void UdisksStorage::LockSetMountPoint(Path mount_point) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; SetMountPoint(mount_point); } @@ -183,7 +183,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept return; } } catch (...) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = std::current_exception(); want_mount = false; cond.notify_all(); @@ -196,7 +196,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept void UdisksStorage::MountWait() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (mounted_storage) /* already mounted */ @@ -239,7 +239,7 @@ try { mount_request.Send(connection, *msg.Get(), [this](auto o) { return OnMountNotify(std::move(o)); }); } catch (...) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = std::current_exception(); want_mount = false; cond.notify_all(); @@ -258,7 +258,7 @@ try { const char *mount_path = i.GetString(); LockSetMountPoint(Path::FromFS(mount_path)); } catch (...) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = std::current_exception(); want_mount = false; cond.notify_all(); @@ -267,7 +267,7 @@ try { void UdisksStorage::UnmountWait() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (!mounted_storage) /* not mounted */ @@ -296,7 +296,7 @@ try { mount_request.Send(connection, *msg.Get(), [this](auto u) { return OnUnmountNotify(std::move(u)); }); } catch (...) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = std::current_exception(); mounted_storage.reset(); cond.notify_all(); @@ -308,12 +308,12 @@ try { using namespace ODBus; reply.CheckThrowError(); - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = {}; mounted_storage.reset(); cond.notify_all(); } catch (...) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; mount_error = std::current_exception(); mounted_storage.reset(); cond.notify_all(); diff --git a/src/tag/ApeLoader.cxx b/src/tag/ApeLoader.cxx index 167645d43..4bfede2bc 100644 --- a/src/tag/ApeLoader.cxx +++ b/src/tag/ApeLoader.cxx @@ -23,7 +23,7 @@ struct ApeFooter { bool tag_ape_scan(InputStream &is, const ApeTagCallback& callback) try { - std::unique_lock lock(is.mutex); + std::unique_lock lock{is.mutex}; if (!is.KnownSize() || !is.CheapSeeking()) return false; diff --git a/src/tag/Builder.cxx b/src/tag/Builder.cxx index 699755170..6d6af1252 100644 --- a/src/tag/Builder.cxx +++ b/src/tag/Builder.cxx @@ -20,7 +20,7 @@ TagBuilder::TagBuilder(const Tag &other) noexcept const std::size_t n = other.num_items; if (n > 0) { items.reserve(other.num_items); - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (std::size_t i = 0; i != n; ++i) items.push_back(tag_pool_dup_item(other.items[i])); } @@ -54,7 +54,7 @@ TagBuilder::operator=(const TagBuilder &other) noexcept items = other.items; /* increment the tag pool refcounters */ - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (auto &i : items) i = tag_pool_dup_item(i); } @@ -170,7 +170,7 @@ TagBuilder::Complement(const Tag &other) noexcept items.reserve(items.size() + n); - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (std::size_t i = 0; i != n; ++i) { TagItem *item = other.items[i]; if (!present[item->type]) @@ -185,7 +185,7 @@ TagBuilder::AddItemUnchecked(TagType type, std::string_view value) noexcept TagItem *i; { - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; i = tag_pool_get_item(type, value); } @@ -228,7 +228,7 @@ TagBuilder::RemoveAll() noexcept return; { - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (auto i : items) tag_pool_put_item(i); } @@ -246,7 +246,7 @@ TagBuilder::RemoveType(TagType type) noexcept const auto begin = items.begin(), end = items.end(); - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; items.erase(std::remove_if(begin, end, [type](TagItem *item) { if (item->type != type) diff --git a/src/tag/Id3Load.cxx b/src/tag/Id3Load.cxx index 19d3da565..85dc1cf43 100644 --- a/src/tag/Id3Load.cxx +++ b/src/tag/Id3Load.cxx @@ -193,7 +193,7 @@ try { UniqueId3Tag tag_id3_load(InputStream &is) try { - std::unique_lock lock(is.mutex); + std::unique_lock lock{is.mutex}; auto tag = tag_id3_find_from_beginning(is, lock); if (tag == nullptr && is.CheapSeeking()) { diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx index 9c119069c..585862c36 100644 --- a/src/tag/Tag.cxx +++ b/src/tag/Tag.cxx @@ -15,7 +15,7 @@ Tag::Clear() noexcept if (num_items > 0) { assert(items != nullptr); - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (unsigned i = 0; i < num_items; ++i) tag_pool_put_item(items[i]); num_items = 0; @@ -32,7 +32,7 @@ Tag::Tag(const Tag &other) noexcept if (num_items > 0) { items = new TagItem *[num_items]; - const std::scoped_lock protect(tag_pool_lock); + const std::scoped_lock protect{tag_pool_lock}; for (unsigned i = 0; i < num_items; i++) items[i] = tag_pool_dup_item(other.items[i]); } diff --git a/src/thread/SafeSingleton.hxx b/src/thread/SafeSingleton.hxx index 632bc62a7..373e821a6 100644 --- a/src/thread/SafeSingleton.hxx +++ b/src/thread/SafeSingleton.hxx @@ -22,7 +22,7 @@ class SafeSingleton { public: template explicit SafeSingleton(Args&&... args) { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; if (ref == 0) instance = new T(std::forward(args)...); @@ -34,7 +34,7 @@ public: } ~SafeSingleton() noexcept { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; if (--ref > 0) return; diff --git a/src/thread/WindowsFuture.hxx b/src/thread/WindowsFuture.hxx index b7e123303..4dcee3310 100644 --- a/src/thread/WindowsFuture.hxx +++ b/src/thread/WindowsFuture.hxx @@ -70,24 +70,24 @@ private: public: bool is_ready() const noexcept { - std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; return ready; } bool already_retrieved() const noexcept { - std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; return retrieved; } void wait() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; condition.wait(lock, [this]() { return ready; }); } template WinFutureStatus wait_for(const std::chrono::duration &timeout_duration) const { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; // deferred function not support yet if (condition.wait_for(lock, timeout_duration, [this]() { return ready; })) { @@ -97,7 +97,7 @@ public: } virtual T &get_value() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; if (retrieved) { throw WinFutureError(WinFutureErrc::future_already_retrieved); } @@ -113,7 +113,7 @@ public: } void set_value(const T &value) { - std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; if (!std::holds_alternative(result)) { throw WinFutureError(WinFutureErrc::promise_already_satisfied); } @@ -123,7 +123,7 @@ public: } void set_value(T &&value) { - std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; if (!std::holds_alternative(result)) { throw WinFutureError(WinFutureErrc::promise_already_satisfied); } @@ -133,7 +133,7 @@ public: } void set_exception(std::exception_ptr eptr) { - std::unique_lock lock(mutex); + const std::lock_guard lock{mutex}; if (!std::holds_alternative(result)) { throw WinFutureError(WinFutureErrc::promise_already_satisfied); } diff --git a/test/TestRewindInputStream.cxx b/test/TestRewindInputStream.cxx index d367316d2..6cc4cec31 100644 --- a/test/TestRewindInputStream.cxx +++ b/test/TestRewindInputStream.cxx @@ -52,7 +52,7 @@ TEST(RewindInputStream, Basic) EXPECT_TRUE(ris.get() != sis); EXPECT_TRUE(ris != nullptr); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; ris->Update(); EXPECT_TRUE(ris->IsReady()); diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx index 6cf604a66..e2b9aad02 100644 --- a/test/dump_text_file.cxx +++ b/test/dump_text_file.cxx @@ -54,7 +54,7 @@ dump_input_stream(InputStreamPtr &&is) dump_text_file(tis); } - const std::scoped_lock protect(is->mutex); + const std::scoped_lock protect{is->mutex}; is->Check(); return 0; diff --git a/test/run_input.cxx b/test/run_input.cxx index 4ae8df388..caa20d7a8 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -149,7 +149,7 @@ dump_input_stream(InputStream &is, FileDescriptor out, { out.SetBinaryMode(); - std::unique_lock lock(is.mutex); + std::unique_lock lock{is.mutex}; if (seek > 0) is.Seek(lock, seek); @@ -195,7 +195,7 @@ class DumpRemoteTagHandler final : public RemoteTagHandler { public: Tag Wait() { - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; cond.wait(lock, [this]{ return done; }); if (error) @@ -206,14 +206,14 @@ public: /* virtual methods from RemoteTagHandler */ void OnRemoteTag(Tag &&_tag) noexcept override { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; tag = std::move(_tag); done = true; cond.notify_all(); } void OnRemoteTagError(std::exception_ptr e) noexcept override { - const std::scoped_lock lock(mutex); + const std::scoped_lock lock{mutex}; error = std::move(e); done = true; cond.notify_all(); diff --git a/test/run_storage.cxx b/test/run_storage.cxx index 09dbe48aa..4ef2c8179 100644 --- a/test/run_storage.cxx +++ b/test/run_storage.cxx @@ -253,7 +253,7 @@ Cat(Storage &storage, const char *path) auto is = storage.OpenFile(path, mutex); assert(is); - std::unique_lock lock(mutex); + std::unique_lock lock{mutex}; WaitReady(*is, lock); Cat(*is, lock, FileDescriptor{STDOUT_FILENO});