Commit 4e0e4c00 authored by Rosen Penev's avatar Rosen Penev

treewide: replace lock_guard with scoped_lock

SonarLint reports the latter to be better: std::scoped_lock basically provides the same feature as std::lock_guard, but is more generic: It can lock several mutexes at the same time, with a deadlock prevention mechanism (see {rule:cpp:S5524}). The equivalent code to perform simultaneous locking with std::lock_guard is significantly more complex. Therefore, it is simpler to use std::scoped_lock all the time, even when locking only one mutex (there will be no performance impact). Signed-off-by: 's avatarRosen Penev <rosenp@gmail.com>
parent a8c77a6f
...@@ -29,7 +29,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks) ...@@ -29,7 +29,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks)
MusicChunkPtr MusicChunkPtr
MusicBuffer::Allocate() noexcept MusicBuffer::Allocate() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return MusicChunkPtr(buffer.Allocate(), MusicChunkDeleter(*this)); return MusicChunkPtr(buffer.Allocate(), MusicChunkDeleter(*this));
} }
...@@ -44,7 +44,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept ...@@ -44,7 +44,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept
chunk->next.reset(); chunk->next.reset();
chunk->other.reset(); chunk->other.reset();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(!chunk->other || !chunk->other->other); assert(!chunk->other || !chunk->other->other);
......
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
#endif #endif
bool IsFull() const noexcept { bool IsFull() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return buffer.IsFull(); return buffer.IsFull();
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
bool bool
MusicPipe::Contains(const MusicChunk *chunk) const noexcept MusicPipe::Contains(const MusicChunk *chunk) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
for (const MusicChunk *i = head.get(); i != nullptr; i = i->next.get()) for (const MusicChunk *i = head.get(); i != nullptr; i = i->next.get())
if (i == chunk) if (i == chunk)
...@@ -41,7 +41,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept ...@@ -41,7 +41,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept
MusicChunkPtr MusicChunkPtr
MusicPipe::Shift() noexcept MusicPipe::Shift() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto chunk = std::move(head); auto chunk = std::move(head);
if (chunk != nullptr) { if (chunk != nullptr) {
...@@ -81,7 +81,7 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept ...@@ -81,7 +81,7 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept
assert(!chunk->IsEmpty()); assert(!chunk->IsEmpty());
assert(chunk->length == 0 || chunk->audio_format.IsValid()); assert(chunk->length == 0 || chunk->audio_format.IsValid());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(size > 0 || !audio_format.IsDefined()); assert(size > 0 || !audio_format.IsDefined());
assert(!audio_format.IsDefined() || assert(!audio_format.IsDefined() ||
......
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
const MusicChunk *Peek() const noexcept { const MusicChunk *Peek() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return head.get(); return head.get();
} }
...@@ -101,7 +101,7 @@ public: ...@@ -101,7 +101,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
unsigned GetSize() const noexcept { unsigned GetSize() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return size; return size;
} }
......
...@@ -98,7 +98,7 @@ RemoteTagCache::ItemResolved(Item &item) noexcept ...@@ -98,7 +98,7 @@ RemoteTagCache::ItemResolved(Item &item) noexcept
void void
RemoteTagCache::InvokeHandlers() noexcept RemoteTagCache::InvokeHandlers() noexcept
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
while (!invoke_list.empty()) { while (!invoke_list.empty()) {
auto &item = invoke_list.front(); auto &item = invoke_list.front();
...@@ -125,7 +125,7 @@ RemoteTagCache::Item::OnRemoteTag(Tag &&_tag) noexcept ...@@ -125,7 +125,7 @@ RemoteTagCache::Item::OnRemoteTag(Tag &&_tag) noexcept
scanner.reset(); scanner.reset();
const std::lock_guard<Mutex> lock(parent.mutex); const std::scoped_lock<Mutex> lock(parent.mutex);
parent.ItemResolved(*this); parent.ItemResolved(*this);
} }
...@@ -137,6 +137,6 @@ RemoteTagCache::Item::OnRemoteTagError(std::exception_ptr e) noexcept ...@@ -137,6 +137,6 @@ RemoteTagCache::Item::OnRemoteTagError(std::exception_ptr e) noexcept
scanner.reset(); scanner.reset();
const std::lock_guard<Mutex> lock(parent.mutex); const std::scoped_lock<Mutex> lock(parent.mutex);
parent.ItemResolved(*this); parent.ItemResolved(*this);
} }
...@@ -67,7 +67,7 @@ protected: ...@@ -67,7 +67,7 @@ protected:
} }
void CancelThread() noexcept override { void CancelThread() noexcept override {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
cancel = true; cancel = true;
cond.notify_one(); cond.notify_one();
} }
...@@ -204,7 +204,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is, ...@@ -204,7 +204,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is,
return false; return false;
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (cancel) if (cancel)
throw StopDecoder(); throw StopDecoder();
} }
......
...@@ -36,7 +36,7 @@ UpdateRemoveService::RunDeferred() noexcept ...@@ -36,7 +36,7 @@ UpdateRemoveService::RunDeferred() noexcept
std::forward_list<std::string> copy; std::forward_list<std::string> copy;
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
std::swap(uris, copy); std::swap(uris, copy);
} }
...@@ -55,7 +55,7 @@ UpdateRemoveService::Remove(std::string &&uri) ...@@ -55,7 +55,7 @@ UpdateRemoveService::Remove(std::string &&uri)
bool was_empty; bool was_empty;
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
was_empty = uris.empty(); was_empty = uris.empty();
uris.emplace_front(std::move(uri)); uris.emplace_front(std::move(uri));
} }
......
...@@ -152,7 +152,7 @@ DecoderBridge::FlushChunk() noexcept ...@@ -152,7 +152,7 @@ DecoderBridge::FlushChunk() noexcept
if (!chunk->IsEmpty()) if (!chunk->IsEmpty())
dc.pipe->Push(std::move(chunk)); dc.pipe->Push(std::move(chunk));
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
dc.client_cond.notify_one(); dc.client_cond.notify_one();
} }
...@@ -214,7 +214,7 @@ DecoderBridge::GetVirtualCommand() noexcept ...@@ -214,7 +214,7 @@ DecoderBridge::GetVirtualCommand() noexcept
DecoderCommand DecoderCommand
DecoderBridge::LockGetVirtualCommand() noexcept DecoderBridge::LockGetVirtualCommand() noexcept
{ {
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
return GetVirtualCommand(); return GetVirtualCommand();
} }
...@@ -274,7 +274,7 @@ DecoderBridge::Ready(const AudioFormat audio_format, ...@@ -274,7 +274,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
seekable); seekable);
{ {
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
dc.SetReady(audio_format, seekable, duration); dc.SetReady(audio_format, seekable, duration);
} }
...@@ -300,7 +300,7 @@ DecoderBridge::GetCommand() noexcept ...@@ -300,7 +300,7 @@ DecoderBridge::GetCommand() noexcept
void void
DecoderBridge::CommandFinished() noexcept DecoderBridge::CommandFinished() noexcept
{ {
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
assert(dc.command != DecoderCommand::NONE || initial_seek_running); assert(dc.command != DecoderCommand::NONE || initial_seek_running);
assert(dc.command != DecoderCommand::SEEK || assert(dc.command != DecoderCommand::SEEK ||
......
...@@ -231,7 +231,7 @@ public: ...@@ -231,7 +231,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockIsIdle() const noexcept { bool LockIsIdle() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return IsIdle(); return IsIdle();
} }
...@@ -241,7 +241,7 @@ public: ...@@ -241,7 +241,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockIsStarting() const noexcept { bool LockIsStarting() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return IsStarting(); return IsStarting();
} }
...@@ -253,7 +253,7 @@ public: ...@@ -253,7 +253,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockHasFailed() const noexcept { bool LockHasFailed() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return HasFailed(); return HasFailed();
} }
...@@ -284,7 +284,7 @@ public: ...@@ -284,7 +284,7 @@ public:
* Like CheckRethrowError(), but locks and unlocks the object. * Like CheckRethrowError(), but locks and unlocks the object.
*/ */
void LockCheckRethrowError() const { void LockCheckRethrowError() const {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
CheckRethrowError(); CheckRethrowError();
} }
...@@ -360,7 +360,7 @@ private: ...@@ -360,7 +360,7 @@ private:
} }
void LockAsynchronousCommand(DecoderCommand cmd) noexcept { void LockAsynchronousCommand(DecoderCommand cmd) noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
command = cmd; command = cmd;
Signal(); Signal();
} }
......
...@@ -262,7 +262,7 @@ static void ...@@ -262,7 +262,7 @@ static void
MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is) MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is)
{ {
{ {
const std::lock_guard<Mutex> protect(bridge.dc.mutex); const std::scoped_lock<Mutex> protect(bridge.dc.mutex);
if (bridge.dc.replay_gain_mode == ReplayGainMode::OFF) if (bridge.dc.replay_gain_mode == ReplayGainMode::OFF)
/* ReplayGain is disabled */ /* ReplayGain is disabled */
return; return;
...@@ -337,7 +337,7 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, std::string_view suffix, ...@@ -337,7 +337,7 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, std::string_view suffix,
DecoderControl &dc = bridge.dc; DecoderControl &dc = bridge.dc;
if (plugin.file_decode != nullptr) { if (plugin.file_decode != nullptr) {
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
return decoder_file_decode(plugin, bridge, path_fs); return decoder_file_decode(plugin, bridge, path_fs);
} else if (plugin.stream_decode != nullptr) { } else if (plugin.stream_decode != nullptr) {
std::unique_lock<Mutex> lock(dc.mutex); std::unique_lock<Mutex> lock(dc.mutex);
...@@ -365,7 +365,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, ...@@ -365,7 +365,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs,
bridge.Reset(); bridge.Reset();
DecoderControl &dc = bridge.dc; DecoderControl &dc = bridge.dc;
const std::lock_guard<Mutex> protect(dc.mutex); const std::scoped_lock<Mutex> protect(dc.mutex);
return decoder_file_decode(plugin, bridge, path_fs); return decoder_file_decode(plugin, bridge, path_fs);
} }
......
...@@ -68,7 +68,7 @@ private: ...@@ -68,7 +68,7 @@ private:
exception = std::current_exception(); exception = std::current_exception();
} }
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
done = true; done = true;
cond.notify_one(); cond.notify_one();
} }
......
...@@ -323,7 +323,7 @@ EventLoop::Run() noexcept ...@@ -323,7 +323,7 @@ EventLoop::Run() noexcept
/* try to handle DeferEvents without WakeFD /* try to handle DeferEvents without WakeFD
overhead */ overhead */
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
HandleInject(); HandleInject();
#endif #endif
...@@ -346,7 +346,7 @@ EventLoop::Run() noexcept ...@@ -346,7 +346,7 @@ EventLoop::Run() noexcept
#ifdef HAVE_THREADED_EVENT_LOOP #ifdef HAVE_THREADED_EVENT_LOOP
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
busy = true; busy = true;
} }
#endif #endif
...@@ -378,7 +378,7 @@ EventLoop::AddInject(InjectEvent &d) noexcept ...@@ -378,7 +378,7 @@ EventLoop::AddInject(InjectEvent &d) noexcept
bool must_wake; bool must_wake;
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
if (d.IsPending()) if (d.IsPending())
return; return;
...@@ -397,7 +397,7 @@ EventLoop::AddInject(InjectEvent &d) noexcept ...@@ -397,7 +397,7 @@ EventLoop::AddInject(InjectEvent &d) noexcept
void void
EventLoop::RemoveInject(InjectEvent &d) noexcept EventLoop::RemoveInject(InjectEvent &d) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (d.IsPending()) if (d.IsPending())
inject.erase(inject.iterator_to(d)); inject.erase(inject.iterator_to(d));
...@@ -424,7 +424,7 @@ EventLoop::OnSocketReady([[maybe_unused]] unsigned flags) noexcept ...@@ -424,7 +424,7 @@ EventLoop::OnSocketReady([[maybe_unused]] unsigned flags) noexcept
wake_fd.Read(); wake_fd.Read();
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
HandleInject(); HandleInject();
} }
......
...@@ -244,7 +244,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept ...@@ -244,7 +244,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size) noexcept
void void
AsyncInputStream::DeferredResume() noexcept AsyncInputStream::DeferredResume() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
try { try {
Resume(); Resume();
...@@ -257,7 +257,7 @@ AsyncInputStream::DeferredResume() noexcept ...@@ -257,7 +257,7 @@ AsyncInputStream::DeferredResume() noexcept
void void
AsyncInputStream::DeferredSeek() noexcept AsyncInputStream::DeferredSeek() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (seek_state != SeekState::SCHEDULED) if (seek_state != SeekState::SCHEDULED)
return; return;
......
...@@ -37,7 +37,7 @@ BufferingInputStream::BufferingInputStream(InputStreamPtr _input) ...@@ -37,7 +37,7 @@ BufferingInputStream::BufferingInputStream(InputStreamPtr _input)
BufferingInputStream::~BufferingInputStream() noexcept BufferingInputStream::~BufferingInputStream() noexcept
{ {
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
stop = true; stop = true;
wake_cond.notify_one(); wake_cond.notify_one();
} }
......
...@@ -97,7 +97,7 @@ InputStream::ReadTag() noexcept ...@@ -97,7 +97,7 @@ InputStream::ReadTag() noexcept
std::unique_ptr<Tag> std::unique_ptr<Tag>
InputStream::LockReadTag() noexcept InputStream::LockReadTag() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return ReadTag(); return ReadTag();
} }
...@@ -152,7 +152,7 @@ InputStream::LockReadFull(void *ptr, size_t _size) ...@@ -152,7 +152,7 @@ InputStream::LockReadFull(void *ptr, size_t _size)
bool bool
InputStream::LockIsEOF() const noexcept InputStream::LockIsEOF() const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return IsEOF(); return IsEOF();
} }
......
...@@ -45,7 +45,7 @@ ThreadInputStream::Stop() noexcept ...@@ -45,7 +45,7 @@ ThreadInputStream::Stop() noexcept
return; return;
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
close = true; close = true;
wake_cond.notify_one(); wake_cond.notify_one();
} }
......
...@@ -37,14 +37,14 @@ InputCacheItem::~InputCacheItem() noexcept ...@@ -37,14 +37,14 @@ InputCacheItem::~InputCacheItem() noexcept
void void
InputCacheItem::AddLease(InputCacheLease &lease) noexcept InputCacheItem::AddLease(InputCacheLease &lease) noexcept
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
leases.push_back(lease); leases.push_back(lease);
} }
void void
InputCacheItem::RemoveLease(InputCacheLease &lease) noexcept InputCacheItem::RemoveLease(InputCacheLease &lease) noexcept
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
auto i = leases.iterator_to(lease); auto i = leases.iterator_to(lease);
if (i == next_lease) if (i == next_lease)
++next_lease; ++next_lease;
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,7 @@ public:
using BufferingInputStream::size; using BufferingInputStream::size;
bool IsInUse() const noexcept { bool IsInUse() const noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
return !leases.empty(); return !leases.empty();
} }
......
...@@ -36,7 +36,7 @@ CacheInputStream::Check() ...@@ -36,7 +36,7 @@ CacheInputStream::Check()
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const std::lock_guard<Mutex> protect(i.mutex); const std::scoped_lock<Mutex> protect(i.mutex);
i.Check(); i.Check();
} }
...@@ -60,7 +60,7 @@ CacheInputStream::IsAvailable() const noexcept ...@@ -60,7 +60,7 @@ CacheInputStream::IsAvailable() const noexcept
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const std::lock_guard<Mutex> protect(i.mutex); const std::scoped_lock<Mutex> protect(i.mutex);
return i.IsAvailable(_offset); return i.IsAvailable(_offset);
} }
...@@ -76,7 +76,7 @@ CacheInputStream::Read(std::unique_lock<Mutex> &lock, ...@@ -76,7 +76,7 @@ CacheInputStream::Read(std::unique_lock<Mutex> &lock,
{ {
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
const std::lock_guard<Mutex> protect(i.mutex); const std::scoped_lock<Mutex> protect(i.mutex);
nbytes = i.Read(lock, _offset, ptr, read_size); nbytes = i.Read(lock, _offset, ptr, read_size);
} }
...@@ -91,6 +91,6 @@ CacheInputStream::OnInputCacheAvailable() noexcept ...@@ -91,6 +91,6 @@ CacheInputStream::OnInputCacheAvailable() noexcept
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const ScopeUnlock unlock(i.mutex); const ScopeUnlock unlock(i.mutex);
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
InvokeOnAvailable(); InvokeOnAvailable();
} }
...@@ -239,7 +239,7 @@ AlsaInputStream::DispatchSockets() noexcept ...@@ -239,7 +239,7 @@ AlsaInputStream::DispatchSockets() noexcept
{ {
non_block.DispatchSockets(*this, capture_handle); non_block.DispatchSockets(*this, capture_handle);
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto w = PrepareWriteBuffer(); auto w = PrepareWriteBuffer();
const snd_pcm_uframes_t w_frames = w.size / frame_size; const snd_pcm_uframes_t w_frames = w.size / frame_size;
......
...@@ -238,7 +238,7 @@ CurlInputStream::OnHeaders(unsigned status, ...@@ -238,7 +238,7 @@ CurlInputStream::OnHeaders(unsigned status,
StringFormat<40>("got HTTP status %u", StringFormat<40>("got HTTP status %u",
status).c_str()); status).c_str());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (IsSeekPending()) { if (IsSeekPending()) {
/* don't update metadata while seeking */ /* don't update metadata while seeking */
...@@ -301,7 +301,7 @@ CurlInputStream::OnData(ConstBuffer<void> data) ...@@ -301,7 +301,7 @@ CurlInputStream::OnData(ConstBuffer<void> data)
{ {
assert(data.size > 0); assert(data.size > 0);
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (IsSeekPending()) if (IsSeekPending())
SeekDone(); SeekDone();
...@@ -317,7 +317,7 @@ CurlInputStream::OnData(ConstBuffer<void> data) ...@@ -317,7 +317,7 @@ CurlInputStream::OnData(ConstBuffer<void> data)
void void
CurlInputStream::OnEnd() CurlInputStream::OnEnd()
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
InvokeOnAvailable(); InvokeOnAvailable();
AsyncInputStream::SetClosed(); AsyncInputStream::SetClosed();
...@@ -326,7 +326,7 @@ CurlInputStream::OnEnd() ...@@ -326,7 +326,7 @@ CurlInputStream::OnEnd()
void void
CurlInputStream::OnError(std::exception_ptr e) noexcept CurlInputStream::OnError(std::exception_ptr e) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
postponed_exception = std::move(e); postponed_exception = std::move(e);
if (IsSeekPending()) if (IsSeekPending())
......
...@@ -141,7 +141,7 @@ NfsInputStream::DoSeek(offset_type new_offset) ...@@ -141,7 +141,7 @@ NfsInputStream::DoSeek(offset_type new_offset)
void void
NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (reconnecting) { if (reconnecting) {
/* reconnect has succeeded */ /* reconnect has succeeded */
...@@ -161,7 +161,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept ...@@ -161,7 +161,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept
void void
NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) noexcept NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(!IsBufferFull()); assert(!IsBufferFull());
assert(IsBufferFull() == (GetBufferSpace() == 0)); assert(IsBufferFull() == (GetBufferSpace() == 0));
AppendToBuffer(data, data_size); AppendToBuffer(data, data_size);
...@@ -174,7 +174,7 @@ NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) noexcept ...@@ -174,7 +174,7 @@ NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) noexcept
void void
NfsInputStream::OnNfsFileError(std::exception_ptr &&e) noexcept NfsInputStream::OnNfsFileError(std::exception_ptr &&e) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (IsPaused()) { if (IsPaused()) {
/* while we're paused, don't report this error to the /* while we're paused, don't report this error to the
......
...@@ -87,7 +87,7 @@ QobuzClient::StartLogin() ...@@ -87,7 +87,7 @@ QobuzClient::StartLogin()
void void
QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(!h.is_linked()); assert(!h.is_linked());
const bool was_empty = handlers.empty(); const bool was_empty = handlers.empty();
...@@ -114,7 +114,7 @@ QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept ...@@ -114,7 +114,7 @@ QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
QobuzSession QobuzSession
QobuzClient::GetSession() const QobuzClient::GetSession() const
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
...@@ -129,7 +129,7 @@ void ...@@ -129,7 +129,7 @@ void
QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept
{ {
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
session = std::move(_session); session = std::move(_session);
login_request.reset(); login_request.reset();
} }
...@@ -141,7 +141,7 @@ void ...@@ -141,7 +141,7 @@ void
QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
{ {
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
error = std::move(_error); error = std::move(_error);
login_request.reset(); login_request.reset();
} }
...@@ -152,7 +152,7 @@ QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept ...@@ -152,7 +152,7 @@ QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
void void
QobuzClient::InvokeHandlers() noexcept QobuzClient::InvokeHandlers() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
while (!handlers.empty()) { while (!handlers.empty()) {
auto &h = handlers.front(); auto &h = handlers.front();
handlers.pop_front(); handlers.pop_front();
......
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
void AddLoginHandler(QobuzSessionHandler &h) noexcept; void AddLoginHandler(QobuzSessionHandler &h) noexcept;
void RemoveLoginHandler(QobuzSessionHandler &h) noexcept { void RemoveLoginHandler(QobuzSessionHandler &h) noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (h.is_linked()) if (h.is_linked())
h.unlink(); h.unlink();
} }
......
...@@ -84,7 +84,7 @@ private: ...@@ -84,7 +84,7 @@ private:
void void
QobuzInputStream::OnQobuzSession() noexcept QobuzInputStream::OnQobuzSession() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
try { try {
const auto session = qobuz_client->GetSession(); const auto session = qobuz_client->GetSession();
...@@ -103,7 +103,7 @@ QobuzInputStream::OnQobuzSession() noexcept ...@@ -103,7 +103,7 @@ QobuzInputStream::OnQobuzSession() noexcept
void void
QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
track_request.reset(); track_request.reset();
try { try {
...@@ -117,7 +117,7 @@ QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept ...@@ -117,7 +117,7 @@ QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept
void void
QobuzInputStream::OnQobuzTrackError(std::exception_ptr e) noexcept QobuzInputStream::OnQobuzTrackError(std::exception_ptr e) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
track_request.reset(); track_request.reset();
Failed(e); Failed(e);
......
...@@ -149,7 +149,7 @@ UringInputStream::OnRead(std::unique_ptr<std::byte[]> data, ...@@ -149,7 +149,7 @@ UringInputStream::OnRead(std::unique_ptr<std::byte[]> data,
{ {
read_operation.reset(); read_operation.reset();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (nbytes == 0) { if (nbytes == 0) {
postponed_exception = std::make_exception_ptr(std::runtime_error("Premature end of file")); postponed_exception = std::make_exception_ptr(std::runtime_error("Premature end of file"));
...@@ -170,7 +170,7 @@ UringInputStream::OnReadError(int error) noexcept ...@@ -170,7 +170,7 @@ UringInputStream::OnReadError(int error) noexcept
{ {
read_operation.reset(); read_operation.reset();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
postponed_exception = std::make_exception_ptr(MakeErrno(error, "Read failed")); postponed_exception = std::make_exception_ptr(MakeErrno(error, "Read failed"));
InvokeOnAvailable(); InvokeOnAvailable();
......
...@@ -40,7 +40,7 @@ CurlGlobal *CurlInit::instance; ...@@ -40,7 +40,7 @@ CurlGlobal *CurlInit::instance;
CurlInit::CurlInit(EventLoop &event_loop) CurlInit::CurlInit(EventLoop &event_loop)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (++ref > 1) { if (++ref > 1) {
assert(&event_loop == &instance->GetEventLoop()); assert(&event_loop == &instance->GetEventLoop());
return; return;
...@@ -56,7 +56,7 @@ CurlInit::CurlInit(EventLoop &event_loop) ...@@ -56,7 +56,7 @@ CurlInit::CurlInit(EventLoop &event_loop)
CurlInit::~CurlInit() noexcept CurlInit::~CurlInit() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (--ref > 0) if (--ref > 0)
return; return;
......
...@@ -105,7 +105,7 @@ AllocatedString ...@@ -105,7 +105,7 @@ AllocatedString
IcuConverter::ToUTF8(std::string_view s) const IcuConverter::ToUTF8(std::string_view s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
ucnv_resetToUnicode(converter); ucnv_resetToUnicode(converter);
...@@ -133,7 +133,7 @@ AllocatedString ...@@ -133,7 +133,7 @@ AllocatedString
IcuConverter::FromUTF8(std::string_view s) const IcuConverter::FromUTF8(std::string_view s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
const auto u = UCharFromUTF8(s); const auto u = UCharFromUTF8(s);
......
...@@ -68,7 +68,7 @@ private: ...@@ -68,7 +68,7 @@ private:
* thread. * thread.
*/ */
void LockSetFinished() noexcept { void LockSetFinished() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
finished = true; finished = true;
cond.notify_one(); cond.notify_one();
} }
......
...@@ -45,7 +45,7 @@ SmbclientContext::New() ...@@ -45,7 +45,7 @@ SmbclientContext::New()
SMBCCTX *ctx; SMBCCTX *ctx;
{ {
const std::lock_guard<Mutex> protect(global_mutex); const std::scoped_lock<Mutex> protect(global_mutex);
ctx = smbc_new_context(); ctx = smbc_new_context();
} }
......
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
~SmbclientContext() noexcept { ~SmbclientContext() noexcept {
if (ctx != nullptr) { if (ctx != nullptr) {
const std::lock_guard<Mutex> protect(global_mutex); const std::scoped_lock<Mutex> protect(global_mutex);
smbc_free_context(ctx, 1); smbc_free_context(ctx, 1);
} }
} }
......
...@@ -62,7 +62,7 @@ UpnpClientGlobalInit(const char* iface) ...@@ -62,7 +62,7 @@ UpnpClientGlobalInit(const char* iface)
UpnpGlobalInit(iface); UpnpGlobalInit(iface);
try { try {
const std::lock_guard<Mutex> protect(upnp_client_init_mutex); const std::scoped_lock<Mutex> protect(upnp_client_init_mutex);
if (upnp_client_ref == 0) if (upnp_client_ref == 0)
DoInit(); DoInit();
} catch (...) { } catch (...) {
...@@ -78,7 +78,7 @@ void ...@@ -78,7 +78,7 @@ void
UpnpClientGlobalFinish() noexcept UpnpClientGlobalFinish() noexcept
{ {
{ {
const std::lock_guard<Mutex> protect(upnp_client_init_mutex); const std::scoped_lock<Mutex> protect(upnp_client_init_mutex);
assert(upnp_client_ref > 0); assert(upnp_client_ref > 0);
if (--upnp_client_ref == 0) if (--upnp_client_ref == 0)
......
...@@ -41,14 +41,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent, ...@@ -41,14 +41,14 @@ UPnPDeviceDirectory::Downloader::Downloader(UPnPDeviceDirectory &_parent,
expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))), expires(std::chrono::seconds(UpnpDiscovery_get_Expires(&disco))),
request(*parent.curl, url.c_str(), *this) request(*parent.curl, url.c_str(), *this)
{ {
const std::lock_guard<Mutex> protect(parent.mutex); const std::scoped_lock<Mutex> protect(parent.mutex);
parent.downloaders.push_back(*this); parent.downloaders.push_back(*this);
} }
void void
UPnPDeviceDirectory::Downloader::Destroy() noexcept UPnPDeviceDirectory::Downloader::Destroy() noexcept
{ {
const std::lock_guard<Mutex> protect(parent.mutex); const std::scoped_lock<Mutex> protect(parent.mutex);
unlink(); unlink();
delete this; delete this;
} }
...@@ -139,7 +139,7 @@ AnnounceLostUPnP(UPnPDiscoveryListener &listener, const UPnPDevice &device) ...@@ -139,7 +139,7 @@ AnnounceLostUPnP(UPnPDiscoveryListener &listener, const UPnPDevice &device)
inline void inline void
UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d) UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
for (auto &i : directories) { for (auto &i : directories) {
if (i.id == d.id) { if (i.id == d.id) {
...@@ -157,7 +157,7 @@ UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d) ...@@ -157,7 +157,7 @@ UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
inline void inline void
UPnPDeviceDirectory::LockRemove(const std::string &id) UPnPDeviceDirectory::LockRemove(const std::string &id)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
for (auto i = directories.begin(), end = directories.end(); for (auto i = directories.begin(), end = directories.end();
i != end; ++i) { i != end; ++i) {
...@@ -265,10 +265,10 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop, ...@@ -265,10 +265,10 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop,
UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept
{ {
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this]() {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
downloaders.clear_and_dispose(DeleteDisposer()); downloaders.clear_and_dispose(DeleteDisposer());
}); });
} }
inline EventLoop & inline EventLoop &
...@@ -308,7 +308,7 @@ UPnPDeviceDirectory::Search() ...@@ -308,7 +308,7 @@ UPnPDeviceDirectory::Search()
std::vector<ContentDirectoryService> std::vector<ContentDirectoryService>
UPnPDeviceDirectory::GetDirectories() UPnPDeviceDirectory::GetDirectories()
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
ExpireDevices(); ExpireDevices();
...@@ -327,7 +327,7 @@ UPnPDeviceDirectory::GetDirectories() ...@@ -327,7 +327,7 @@ UPnPDeviceDirectory::GetDirectories()
ContentDirectoryService ContentDirectoryService
UPnPDeviceDirectory::GetServer(std::string_view friendly_name) UPnPDeviceDirectory::GetServer(std::string_view friendly_name)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
ExpireDevices(); ExpireDevices();
......
...@@ -56,7 +56,7 @@ DoInit(const char* iface) ...@@ -56,7 +56,7 @@ DoInit(const char* iface)
void void
UpnpGlobalInit(const char* iface) UpnpGlobalInit(const char* iface)
{ {
const std::lock_guard<Mutex> protect(upnp_init_mutex); const std::scoped_lock<Mutex> protect(upnp_init_mutex);
if (upnp_ref == 0) if (upnp_ref == 0)
DoInit(iface); DoInit(iface);
...@@ -67,7 +67,7 @@ UpnpGlobalInit(const char* iface) ...@@ -67,7 +67,7 @@ UpnpGlobalInit(const char* iface)
void void
UpnpGlobalFinish() noexcept UpnpGlobalFinish() noexcept
{ {
const std::lock_guard<Mutex> protect(upnp_init_mutex); const std::scoped_lock<Mutex> protect(upnp_init_mutex);
assert(upnp_ref > 0); assert(upnp_ref > 0);
......
...@@ -52,7 +52,7 @@ mixer_open(Mixer *mixer) ...@@ -52,7 +52,7 @@ mixer_open(Mixer *mixer)
{ {
assert(mixer != nullptr); assert(mixer != nullptr);
const std::lock_guard<Mutex> protect(mixer->mutex); const std::scoped_lock<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
return; return;
...@@ -82,7 +82,7 @@ mixer_close(Mixer *mixer) ...@@ -82,7 +82,7 @@ mixer_close(Mixer *mixer)
{ {
assert(mixer != nullptr); assert(mixer != nullptr);
const std::lock_guard<Mutex> protect(mixer->mutex); const std::scoped_lock<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
mixer_close_internal(mixer); mixer_close_internal(mixer);
...@@ -119,7 +119,7 @@ mixer_get_volume(Mixer *mixer) ...@@ -119,7 +119,7 @@ mixer_get_volume(Mixer *mixer)
if (mixer->plugin.global && !mixer->failed) if (mixer->plugin.global && !mixer->failed)
mixer_open(mixer); mixer_open(mixer);
const std::lock_guard<Mutex> protect(mixer->mutex); const std::scoped_lock<Mutex> protect(mixer->mutex);
if (mixer->open) { if (mixer->open) {
try { try {
...@@ -143,7 +143,7 @@ mixer_set_volume(Mixer *mixer, unsigned volume) ...@@ -143,7 +143,7 @@ mixer_set_volume(Mixer *mixer, unsigned volume)
if (mixer->plugin.global && !mixer->failed) if (mixer->plugin.global && !mixer->failed)
mixer_open(mixer); mixer_open(mixer);
const std::lock_guard<Mutex> protect(mixer->mutex); const std::scoped_lock<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
mixer->SetVolume(volume); mixer->SetVolume(volume);
......
...@@ -99,7 +99,7 @@ void ...@@ -99,7 +99,7 @@ void
SmbclientNeighborExplorer::Close() noexcept SmbclientNeighborExplorer::Close() noexcept
{ {
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
quit = true; quit = true;
cond.notify_one(); cond.notify_one();
} }
...@@ -110,7 +110,7 @@ SmbclientNeighborExplorer::Close() noexcept ...@@ -110,7 +110,7 @@ SmbclientNeighborExplorer::Close() noexcept
NeighborExplorer::List NeighborExplorer::List
SmbclientNeighborExplorer::GetList() const noexcept SmbclientNeighborExplorer::GetList() const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return list; return list;
} }
......
...@@ -175,7 +175,7 @@ UdisksNeighborExplorer::Close() noexcept ...@@ -175,7 +175,7 @@ UdisksNeighborExplorer::Close() noexcept
NeighborExplorer::List NeighborExplorer::List
UdisksNeighborExplorer::GetList() const noexcept UdisksNeighborExplorer::GetList() const noexcept
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
NeighborExplorer::List result; NeighborExplorer::List result;
...@@ -192,7 +192,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept ...@@ -192,7 +192,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept
const NeighborInfo info = ToNeighborInfo(o); const NeighborInfo info = ToNeighborInfo(o);
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto i = by_uri.emplace(o.GetUri(), info); auto i = by_uri.emplace(o.GetUri(), info);
if (!i.second) if (!i.second)
i.first->second = info; i.first->second = info;
......
...@@ -79,7 +79,7 @@ AudioOutputControl::Steal() noexcept ...@@ -79,7 +79,7 @@ AudioOutputControl::Steal() noexcept
StopThread(); StopThread();
/* now we can finally remove it */ /* now we can finally remove it */
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return std::exchange(output, nullptr); return std::exchange(output, nullptr);
} }
...@@ -91,7 +91,7 @@ AudioOutputControl::ReplaceDummy(std::unique_ptr<FilteredAudioOutput> new_output ...@@ -91,7 +91,7 @@ AudioOutputControl::ReplaceDummy(std::unique_ptr<FilteredAudioOutput> new_output
assert(new_output); assert(new_output);
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
output = std::move(new_output); output = std::move(new_output);
enabled = _enabled; enabled = _enabled;
} }
...@@ -146,7 +146,7 @@ AudioOutputControl::SetAttribute(std::string &&attribute_name, ...@@ -146,7 +146,7 @@ AudioOutputControl::SetAttribute(std::string &&attribute_name,
bool bool
AudioOutputControl::LockSetEnabled(bool new_value) noexcept AudioOutputControl::LockSetEnabled(bool new_value) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (new_value == enabled) if (new_value == enabled)
return false; return false;
...@@ -158,7 +158,7 @@ AudioOutputControl::LockSetEnabled(bool new_value) noexcept ...@@ -158,7 +158,7 @@ AudioOutputControl::LockSetEnabled(bool new_value) noexcept
bool bool
AudioOutputControl::LockToggleEnabled() noexcept AudioOutputControl::LockToggleEnabled() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return enabled = !enabled; return enabled = !enabled;
} }
...@@ -342,14 +342,14 @@ AudioOutputControl::IsChunkConsumed(const MusicChunk &chunk) const noexcept ...@@ -342,14 +342,14 @@ AudioOutputControl::IsChunkConsumed(const MusicChunk &chunk) const noexcept
bool bool
AudioOutputControl::LockIsChunkConsumed(const MusicChunk &chunk) const noexcept AudioOutputControl::LockIsChunkConsumed(const MusicChunk &chunk) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return IsChunkConsumed(chunk); return IsChunkConsumed(chunk);
} }
void void
AudioOutputControl::LockPlay() noexcept AudioOutputControl::LockPlay() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
...@@ -371,7 +371,7 @@ AudioOutputControl::LockPauseAsync() noexcept ...@@ -371,7 +371,7 @@ AudioOutputControl::LockPauseAsync() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
...@@ -381,7 +381,7 @@ AudioOutputControl::LockPauseAsync() noexcept ...@@ -381,7 +381,7 @@ AudioOutputControl::LockPauseAsync() noexcept
void void
AudioOutputControl::LockDrainAsync() noexcept AudioOutputControl::LockDrainAsync() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
...@@ -394,7 +394,7 @@ AudioOutputControl::LockCancelAsync() noexcept ...@@ -394,7 +394,7 @@ AudioOutputControl::LockCancelAsync() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (IsOpen()) { if (IsOpen()) {
allow_play = false; allow_play = false;
...@@ -405,7 +405,7 @@ AudioOutputControl::LockCancelAsync() noexcept ...@@ -405,7 +405,7 @@ AudioOutputControl::LockCancelAsync() noexcept
void void
AudioOutputControl::LockAllowPlay() noexcept AudioOutputControl::LockAllowPlay() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
allow_play = true; allow_play = true;
if (IsOpen()) if (IsOpen())
...@@ -457,7 +457,7 @@ AudioOutputControl::BeginDestroy() noexcept ...@@ -457,7 +457,7 @@ AudioOutputControl::BeginDestroy() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (!killed) { if (!killed) {
killed = true; killed = true;
CommandAsync(Command::KILL); CommandAsync(Command::KILL);
......
...@@ -405,7 +405,7 @@ public: ...@@ -405,7 +405,7 @@ public:
void EnableDisableAsync(); void EnableDisableAsync();
void LockEnableDisableAsync() { void LockEnableDisableAsync() {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
EnableDisableAsync(); EnableDisableAsync();
} }
...@@ -480,7 +480,7 @@ public: ...@@ -480,7 +480,7 @@ public:
* Locking wrapper for ClearTailChunk(). * Locking wrapper for ClearTailChunk().
*/ */
void LockClearTailChunk(const MusicChunk &chunk) noexcept { void LockClearTailChunk(const MusicChunk &chunk) noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
ClearTailChunk(chunk); ClearTailChunk(chunk);
} }
......
...@@ -229,7 +229,7 @@ MultipleOutputs::Open(const AudioFormat audio_format) ...@@ -229,7 +229,7 @@ MultipleOutputs::Open(const AudioFormat audio_format)
std::exception_ptr first_error; std::exception_ptr first_error;
for (const auto &ao : outputs) { for (const auto &ao : outputs) {
const std::lock_guard<Mutex> lock(ao->mutex); const std::scoped_lock<Mutex> lock(ao->mutex);
if (ao->IsEnabled()) if (ao->IsEnabled())
enabled = true; enabled = true;
......
...@@ -41,7 +41,7 @@ audio_output_state_save(BufferedOutputStream &os, ...@@ -41,7 +41,7 @@ audio_output_state_save(BufferedOutputStream &os,
{ {
for (unsigned i = 0, n = outputs.Size(); i != n; ++i) { for (unsigned i = 0, n = outputs.Size(); i != n; ++i) {
const auto &ao = outputs.Get(i); const auto &ao = outputs.Get(i);
const std::lock_guard<Mutex> lock(ao.mutex); const std::scoped_lock<Mutex> lock(ao.mutex);
os.Format(AUDIO_DEVICE_STATE "%d:%s\n", os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
ao.IsEnabled(), ao.GetName()); ao.IsEnabled(), ao.GetName());
......
...@@ -311,13 +311,13 @@ private: ...@@ -311,13 +311,13 @@ private:
gcc_pure gcc_pure
bool LockIsActive() const noexcept { bool LockIsActive() const noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
return active; return active;
} }
gcc_pure gcc_pure
bool LockIsActiveAndNotWaiting() const noexcept { bool LockIsActiveAndNotWaiting() const noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
return active && !waiting; return active && !waiting;
} }
...@@ -383,7 +383,7 @@ private: ...@@ -383,7 +383,7 @@ private:
void LockCaughtError() noexcept { void LockCaughtError() noexcept {
period_buffer.Clear(); period_buffer.Clear();
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
error = std::current_exception(); error = std::current_exception();
active = false; active = false;
waiting = false; waiting = false;
...@@ -398,7 +398,7 @@ private: ...@@ -398,7 +398,7 @@ private:
*/ */
void OnSilenceTimer() noexcept { void OnSilenceTimer() noexcept {
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
assert(active); assert(active);
waiting = false; waiting = false;
} }
...@@ -464,7 +464,7 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block) ...@@ -464,7 +464,7 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block)
std::map<std::string, std::string> std::map<std::string, std::string>
AlsaOutput::GetAttributes() const noexcept AlsaOutput::GetAttributes() const noexcept
{ {
const std::lock_guard<Mutex> lock(attributes_mutex); const std::scoped_lock<Mutex> lock(attributes_mutex);
return { return {
{"allowed_formats", Alsa::ToString(allowed_formats)}, {"allowed_formats", Alsa::ToString(allowed_formats)},
...@@ -478,11 +478,11 @@ void ...@@ -478,11 +478,11 @@ void
AlsaOutput::SetAttribute(std::string &&name, std::string &&value) AlsaOutput::SetAttribute(std::string &&name, std::string &&value)
{ {
if (name == "allowed_formats") { if (name == "allowed_formats") {
const std::lock_guard<Mutex> lock(attributes_mutex); const std::scoped_lock<Mutex> lock(attributes_mutex);
allowed_formats = Alsa::AllowedFormat::ParseList(value); allowed_formats = Alsa::AllowedFormat::ParseList(value);
#ifdef ENABLE_DSD #ifdef ENABLE_DSD
} else if (name == "dop") { } else if (name == "dop") {
const std::lock_guard<Mutex> lock(attributes_mutex); const std::scoped_lock<Mutex> lock(attributes_mutex);
if (value == "0") if (value == "0")
dop_setting = false; dop_setting = false;
else if (value == "1") else if (value == "1")
...@@ -790,7 +790,7 @@ AlsaOutput::Open(AudioFormat &audio_format) ...@@ -790,7 +790,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
#endif #endif
{ {
const std::lock_guard<Mutex> lock(attributes_mutex); const std::scoped_lock<Mutex> lock(attributes_mutex);
#ifdef ENABLE_DSD #ifdef ENABLE_DSD
dop = dop_setting; dop = dop_setting;
#endif #endif
...@@ -966,7 +966,7 @@ AlsaOutput::CopyRingToPeriodBuffer() noexcept ...@@ -966,7 +966,7 @@ AlsaOutput::CopyRingToPeriodBuffer() noexcept
period_buffer.AppendBytes(nbytes); period_buffer.AppendBytes(nbytes);
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
/* notify the OutputThread that there is now /* notify the OutputThread that there is now
room in ring_buffer */ room in ring_buffer */
cond.notify_one(); cond.notify_one();
...@@ -1276,7 +1276,7 @@ try { ...@@ -1276,7 +1276,7 @@ try {
} }
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
assert(active); assert(active);
...@@ -1316,7 +1316,7 @@ try { ...@@ -1316,7 +1316,7 @@ try {
smaller than the ALSA-PCM buffer */ smaller than the ALSA-PCM buffer */
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
waiting = true; waiting = true;
cond.notify_one(); cond.notify_one();
} }
......
...@@ -121,7 +121,7 @@ private: ...@@ -121,7 +121,7 @@ private:
void Disconnect() noexcept; void Disconnect() noexcept;
void Shutdown(const char *reason) noexcept { void Shutdown(const char *reason) noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
error = std::make_exception_ptr(FormatRuntimeError("JACK connection shutdown: %s", error = std::make_exception_ptr(FormatRuntimeError("JACK connection shutdown: %s",
reason)); reason));
} }
...@@ -185,7 +185,7 @@ public: ...@@ -185,7 +185,7 @@ public:
private: private:
bool LockWasShutdown() const noexcept { bool LockWasShutdown() const noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
return !!error; return !!error;
} }
}; };
...@@ -700,7 +700,7 @@ JackOutput::Play(const void *chunk, size_t size) ...@@ -700,7 +700,7 @@ JackOutput::Play(const void *chunk, size_t size)
while (true) { while (true) {
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
...@@ -730,7 +730,7 @@ inline bool ...@@ -730,7 +730,7 @@ inline bool
JackOutput::Pause() JackOutput::Pause()
{ {
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
interrupted = false; interrupted = false;
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
......
...@@ -47,7 +47,7 @@ HttpdClient::Close() noexcept ...@@ -47,7 +47,7 @@ HttpdClient::Close() noexcept
void void
HttpdClient::LockClose() noexcept HttpdClient::LockClose() noexcept
{ {
const std::lock_guard<Mutex> protect(httpd.mutex); const std::scoped_lock<Mutex> protect(httpd.mutex);
Close(); Close();
} }
...@@ -251,7 +251,7 @@ HttpdClient::GetBytesTillMetaData() const noexcept ...@@ -251,7 +251,7 @@ HttpdClient::GetBytesTillMetaData() const noexcept
inline bool inline bool
HttpdClient::TryWrite() noexcept HttpdClient::TryWrite() noexcept
{ {
const std::lock_guard<Mutex> protect(httpd.mutex); const std::scoped_lock<Mutex> protect(httpd.mutex);
assert(state == State::RESPONSE); assert(state == State::RESPONSE);
......
...@@ -202,7 +202,7 @@ public: ...@@ -202,7 +202,7 @@ public:
*/ */
gcc_pure gcc_pure
bool LockHasClients() const noexcept { bool LockHasClients() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return HasClients(); return HasClients();
} }
......
...@@ -104,7 +104,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept ...@@ -104,7 +104,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept
/* this method runs in the IOThread; it broadcasts pages from /* this method runs in the IOThread; it broadcasts pages from
our own queue to all clients */ our own queue to all clients */
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
while (!pages.empty()) { while (!pages.empty()) {
PagePtr page = std::move(pages.front()); PagePtr page = std::move(pages.front());
...@@ -126,7 +126,7 @@ HttpdOutput::OnAccept(UniqueSocketDescriptor fd, ...@@ -126,7 +126,7 @@ HttpdOutput::OnAccept(UniqueSocketDescriptor fd,
/* the listener socket has become readable - a client has /* the listener socket has become readable - a client has
connected */ connected */
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
/* can we allow additional client */ /* can we allow additional client */
if (open && (clients_max == 0 || clients.size() < clients_max)) if (open && (clients_max == 0 || clients.size() < clients_max))
...@@ -186,7 +186,7 @@ HttpdOutput::Open(AudioFormat &audio_format) ...@@ -186,7 +186,7 @@ HttpdOutput::Open(AudioFormat &audio_format)
assert(!open); assert(!open);
assert(clients.empty()); assert(clients.empty());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
OpenEncoder(audio_format); OpenEncoder(audio_format);
...@@ -208,7 +208,7 @@ HttpdOutput::Close() noexcept ...@@ -208,7 +208,7 @@ HttpdOutput::Close() noexcept
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this](){
defer_broadcast.Cancel(); defer_broadcast.Cancel();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
open = false; open = false;
clients.clear_and_dispose(DeleteDisposer()); clients.clear_and_dispose(DeleteDisposer());
}); });
...@@ -261,7 +261,7 @@ HttpdOutput::BroadcastPage(PagePtr page) noexcept ...@@ -261,7 +261,7 @@ HttpdOutput::BroadcastPage(PagePtr page) noexcept
assert(page != nullptr); assert(page != nullptr);
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
pages.emplace(std::move(page)); pages.emplace(std::move(page));
} }
...@@ -281,7 +281,7 @@ HttpdOutput::BroadcastFromEncoder() ...@@ -281,7 +281,7 @@ HttpdOutput::BroadcastFromEncoder()
PagePtr page; PagePtr page;
while ((page = ReadPage()) != nullptr) { while ((page = ReadPage()) != nullptr) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
pages.emplace(std::move(page)); pages.emplace(std::move(page));
empty = false; empty = false;
} }
...@@ -373,7 +373,7 @@ HttpdOutput::SendTag(const Tag &tag) ...@@ -373,7 +373,7 @@ HttpdOutput::SendTag(const Tag &tag)
metadata = icy_server_metadata_page(tag, &types[0]); metadata = icy_server_metadata_page(tag, &types[0]);
if (metadata != nullptr) { if (metadata != nullptr) {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
for (auto &client : clients) for (auto &client : clients)
client.PushMetaData(metadata); client.PushMetaData(metadata);
} }
...@@ -383,7 +383,7 @@ HttpdOutput::SendTag(const Tag &tag) ...@@ -383,7 +383,7 @@ HttpdOutput::SendTag(const Tag &tag)
inline void inline void
HttpdOutput::CancelAllClients() noexcept HttpdOutput::CancelAllClients() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
while (!pages.empty()) { while (!pages.empty()) {
PagePtr page = std::move(pages.front()); PagePtr page = std::move(pages.front());
......
...@@ -398,7 +398,7 @@ SlesOutput::Cancel() noexcept ...@@ -398,7 +398,7 @@ SlesOutput::Cancel() noexcept
LogWarning(sles_domain, LogWarning(sles_domain,
"AndroidSimpleBufferQueue.Clear() failed"); "AndroidSimpleBufferQueue.Clear() failed");
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
n_queued = 0; n_queued = 0;
filled = 0; filled = 0;
} }
...@@ -423,7 +423,7 @@ SlesOutput::Pause() ...@@ -423,7 +423,7 @@ SlesOutput::Pause()
inline void inline void
SlesOutput::PlayedCallback() SlesOutput::PlayedCallback()
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
assert(n_queued > 0); assert(n_queued > 0);
--n_queued; --n_queued;
cond.notify_one(); cond.notify_one();
......
...@@ -53,7 +53,7 @@ SnapcastClient::Close() noexcept ...@@ -53,7 +53,7 @@ SnapcastClient::Close() noexcept
void void
SnapcastClient::LockClose() noexcept SnapcastClient::LockClose() noexcept
{ {
const std::lock_guard<Mutex> protect(output.mutex); const std::scoped_lock<Mutex> protect(output.mutex);
Close(); Close();
} }
...@@ -70,7 +70,7 @@ SnapcastClient::Push(SnapcastChunkPtr chunk) noexcept ...@@ -70,7 +70,7 @@ SnapcastClient::Push(SnapcastChunkPtr chunk) noexcept
SnapcastChunkPtr SnapcastChunkPtr
SnapcastClient::LockPopQueue() noexcept SnapcastClient::LockPopQueue() noexcept
{ {
const std::lock_guard<Mutex> protect(output.mutex); const std::scoped_lock<Mutex> protect(output.mutex);
if (chunks.empty()) if (chunks.empty())
return nullptr; return nullptr;
......
...@@ -134,7 +134,7 @@ public: ...@@ -134,7 +134,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
bool LockHasClients() const noexcept { bool LockHasClients() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return HasClients(); return HasClients();
} }
......
...@@ -114,7 +114,7 @@ SnapcastOutput::OnAccept(UniqueSocketDescriptor fd, ...@@ -114,7 +114,7 @@ SnapcastOutput::OnAccept(UniqueSocketDescriptor fd,
/* the listener socket has become readable - a client has /* the listener socket has become readable - a client has
connected */ connected */
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
/* can we allow additional client */ /* can we allow additional client */
if (open) if (open)
...@@ -152,7 +152,7 @@ SnapcastOutput::Open(AudioFormat &audio_format) ...@@ -152,7 +152,7 @@ SnapcastOutput::Open(AudioFormat &audio_format)
assert(!open); assert(!open);
assert(clients.empty()); assert(clients.empty());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
OpenEncoder(audio_format); OpenEncoder(audio_format);
...@@ -174,7 +174,7 @@ SnapcastOutput::Close() noexcept ...@@ -174,7 +174,7 @@ SnapcastOutput::Close() noexcept
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this](){
inject_event.Cancel(); inject_event.Cancel();
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
open = false; open = false;
clients.clear_and_dispose(DeleteDisposer{}); clients.clear_and_dispose(DeleteDisposer{});
}); });
...@@ -188,7 +188,7 @@ SnapcastOutput::Close() noexcept ...@@ -188,7 +188,7 @@ SnapcastOutput::Close() noexcept
void void
SnapcastOutput::OnInject() noexcept SnapcastOutput::OnInject() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
while (!chunks.empty()) { while (!chunks.empty()) {
const auto chunk = std::move(chunks.front()); const auto chunk = std::move(chunks.front());
...@@ -296,7 +296,7 @@ SnapcastOutput::SendTag(const Tag &tag) ...@@ -296,7 +296,7 @@ SnapcastOutput::SendTag(const Tag &tag)
const ConstBuffer payload(json.data(), json.size()); const ConstBuffer payload(json.data(), json.size());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
// TODO: enqueue StreamTags, don't send directly // TODO: enqueue StreamTags, don't send directly
for (auto &client : clients) for (auto &client : clients)
client.SendStreamTags(payload.ToVoid()); client.SendStreamTags(payload.ToVoid());
...@@ -344,7 +344,7 @@ SnapcastOutput::Play(const void *chunk, size_t size) ...@@ -344,7 +344,7 @@ SnapcastOutput::Play(const void *chunk, size_t size)
unflushed_input = 0; unflushed_input = 0;
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (chunks.empty()) if (chunks.empty())
inject_event.Schedule(); inject_event.Schedule();
...@@ -382,7 +382,7 @@ SnapcastOutput::Drain() ...@@ -382,7 +382,7 @@ SnapcastOutput::Drain()
void void
SnapcastOutput::Cancel() noexcept SnapcastOutput::Cancel() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
ClearQueue(chunks); ClearQueue(chunks);
......
...@@ -160,7 +160,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept ...@@ -160,7 +160,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept
void void
PlayerControl::LockSetBorderPause(bool _border_pause) noexcept PlayerControl::LockSetBorderPause(bool _border_pause) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
border_pause = _border_pause; border_pause = _border_pause;
} }
...@@ -198,14 +198,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept ...@@ -198,14 +198,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept
void void
PlayerControl::LockClearError() noexcept PlayerControl::LockClearError() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
ClearError(); ClearError();
} }
void void
PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
tagged_song.reset(); tagged_song.reset();
tagged_song = std::make_unique<DetachedSong>(song); tagged_song = std::make_unique<DetachedSong>(song);
} }
...@@ -225,7 +225,7 @@ PlayerControl::ReadTaggedSong() noexcept ...@@ -225,7 +225,7 @@ PlayerControl::ReadTaggedSong() noexcept
std::unique_ptr<DetachedSong> std::unique_ptr<DetachedSong>
PlayerControl::LockReadTaggedSong() noexcept PlayerControl::LockReadTaggedSong() noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return ReadTaggedSong(); return ReadTaggedSong();
} }
......
...@@ -248,7 +248,7 @@ public: ...@@ -248,7 +248,7 @@ public:
* Like CheckRethrowError(), but locks and unlocks the object. * Like CheckRethrowError(), but locks and unlocks the object.
*/ */
void LockCheckRethrowError() const { void LockCheckRethrowError() const {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
CheckRethrowError(); CheckRethrowError();
} }
...@@ -317,7 +317,7 @@ public: ...@@ -317,7 +317,7 @@ public:
} }
void LockSetReplayGainMode(ReplayGainMode _mode) noexcept { void LockSetReplayGainMode(ReplayGainMode _mode) noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
replay_gain_mode = _mode; replay_gain_mode = _mode;
} }
...@@ -340,7 +340,7 @@ public: ...@@ -340,7 +340,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
SyncInfo LockGetSyncInfo() const noexcept { SyncInfo LockGetSyncInfo() const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return {state, next_song != nullptr}; return {state, next_song != nullptr};
} }
...@@ -362,7 +362,7 @@ private: ...@@ -362,7 +362,7 @@ private:
* this function. * this function.
*/ */
void LockSignal() noexcept { void LockSignal() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
Signal(); Signal();
} }
...@@ -415,7 +415,7 @@ private: ...@@ -415,7 +415,7 @@ private:
} }
void LockCommandFinished() noexcept { void LockCommandFinished() noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
CommandFinished(); CommandFinished();
} }
...@@ -510,7 +510,7 @@ private: ...@@ -510,7 +510,7 @@ private:
} }
void LockSetOutputError(std::exception_ptr &&_error) noexcept { void LockSetOutputError(std::exception_ptr &&_error) noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
SetOutputError(std::move(_error)); SetOutputError(std::move(_error));
} }
......
...@@ -818,7 +818,7 @@ PlayerControl::PlayChunk(DetachedSong &song, MusicChunkPtr chunk, ...@@ -818,7 +818,7 @@ PlayerControl::PlayChunk(DetachedSong &song, MusicChunkPtr chunk,
return; return;
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
bit_rate = chunk->bit_rate; bit_rate = chunk->bit_rate;
} }
...@@ -942,7 +942,7 @@ Player::PlayNextChunk() noexcept ...@@ -942,7 +942,7 @@ Player::PlayNextChunk() noexcept
return false; return false;
} }
const std::lock_guard<Mutex> lock(pc.mutex); const std::scoped_lock<Mutex> lock(pc.mutex);
/* this formula should prevent that the decoder gets woken up /* this formula should prevent that the decoder gets woken up
with each chunk; it is more efficient to make it decode a with each chunk; it is more efficient to make it decode a
......
...@@ -194,7 +194,7 @@ CompositeStorage::~CompositeStorage() = default; ...@@ -194,7 +194,7 @@ CompositeStorage::~CompositeStorage() = default;
Storage * Storage *
CompositeStorage::GetMount(std::string_view uri) noexcept CompositeStorage::GetMount(std::string_view uri) noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto result = FindStorage(uri); auto result = FindStorage(uri);
if (!result.uri.empty()) if (!result.uri.empty())
...@@ -207,7 +207,7 @@ CompositeStorage::GetMount(std::string_view uri) noexcept ...@@ -207,7 +207,7 @@ CompositeStorage::GetMount(std::string_view uri) noexcept
void void
CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage) CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
Directory &directory = root.Make(uri); Directory &directory = root.Make(uri);
assert(!directory.storage); assert(!directory.storage);
...@@ -217,7 +217,7 @@ CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage) ...@@ -217,7 +217,7 @@ CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage)
bool bool
CompositeStorage::Unmount(const char *uri) CompositeStorage::Unmount(const char *uri)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return root.Unmount(uri); return root.Unmount(uri);
} }
...@@ -246,7 +246,7 @@ CompositeStorage::FindStorage(std::string_view uri) const noexcept ...@@ -246,7 +246,7 @@ CompositeStorage::FindStorage(std::string_view uri) const noexcept
StorageFileInfo StorageFileInfo
CompositeStorage::GetInfo(std::string_view uri, bool follow) CompositeStorage::GetInfo(std::string_view uri, bool follow)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
std::exception_ptr error; std::exception_ptr error;
...@@ -272,7 +272,7 @@ CompositeStorage::GetInfo(std::string_view uri, bool follow) ...@@ -272,7 +272,7 @@ CompositeStorage::GetInfo(std::string_view uri, bool follow)
std::unique_ptr<StorageDirectoryReader> std::unique_ptr<StorageDirectoryReader>
CompositeStorage::OpenDirectory(std::string_view uri) CompositeStorage::OpenDirectory(std::string_view uri)
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
const Directory *directory = f.directory->Find(f.uri); const Directory *directory = f.directory->Find(f.uri);
...@@ -299,7 +299,7 @@ CompositeStorage::OpenDirectory(std::string_view uri) ...@@ -299,7 +299,7 @@ CompositeStorage::OpenDirectory(std::string_view uri)
std::string std::string
CompositeStorage::MapUTF8(std::string_view uri) const noexcept CompositeStorage::MapUTF8(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
...@@ -311,7 +311,7 @@ CompositeStorage::MapUTF8(std::string_view uri) const noexcept ...@@ -311,7 +311,7 @@ CompositeStorage::MapUTF8(std::string_view uri) const noexcept
AllocatedPath AllocatedPath
CompositeStorage::MapFS(std::string_view uri) const noexcept CompositeStorage::MapFS(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
...@@ -323,7 +323,7 @@ CompositeStorage::MapFS(std::string_view uri) const noexcept ...@@ -323,7 +323,7 @@ CompositeStorage::MapFS(std::string_view uri) const noexcept
std::string_view std::string_view
CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (root.storage != nullptr) { if (root.storage != nullptr) {
auto result = root.storage->MapToRelativeUTF8(uri); auto result = root.storage->MapToRelativeUTF8(uri);
......
...@@ -115,7 +115,7 @@ public: ...@@ -115,7 +115,7 @@ public:
*/ */
template<typename T> template<typename T>
void VisitMounts(T t) const { void VisitMounts(T t) const {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
std::string uri; std::string uri;
VisitMounts(uri, root, t); VisitMounts(uri, root, t);
} }
...@@ -125,7 +125,7 @@ public: ...@@ -125,7 +125,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::nonnull]] [[gnu::pure]] [[gnu::nonnull]]
bool IsMounted(const char *storage_uri) const noexcept { bool IsMounted(const char *storage_uri) const noexcept {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
return IsMounted(root, storage_uri); return IsMounted(root, storage_uri);
} }
......
...@@ -131,7 +131,7 @@ protected: ...@@ -131,7 +131,7 @@ protected:
} }
void LockSetDone() { void LockSetDone() {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
SetDone(); SetDone();
} }
...@@ -149,7 +149,7 @@ private: ...@@ -149,7 +149,7 @@ private:
/* virtual methods from CurlResponseHandler */ /* virtual methods from CurlResponseHandler */
void OnError(std::exception_ptr e) noexcept final { void OnError(std::exception_ptr e) noexcept final {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
postponed_error = std::move(e); postponed_error = std::move(e);
SetDone(); SetDone();
} }
......
...@@ -139,7 +139,7 @@ private: ...@@ -139,7 +139,7 @@ private:
void SetState(State _state) noexcept { void SetState(State _state) noexcept {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
state = _state; state = _state;
cond.notify_all(); cond.notify_all();
} }
...@@ -147,7 +147,7 @@ private: ...@@ -147,7 +147,7 @@ private:
void SetState(State _state, std::exception_ptr &&e) noexcept { void SetState(State _state, std::exception_ptr &&e) noexcept {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
state = _state; state = _state;
last_exception = std::move(e); last_exception = std::move(e);
cond.notify_all(); cond.notify_all();
......
...@@ -102,7 +102,7 @@ GetInfo(SmbclientContext &ctx, Mutex &mutex, const char *path) ...@@ -102,7 +102,7 @@ GetInfo(SmbclientContext &ctx, Mutex &mutex, const char *path)
struct stat st; struct stat st;
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
if (ctx.Stat(path, st) != 0) if (ctx.Stat(path, st) != 0)
throw MakeErrno("Failed to access file"); throw MakeErrno("Failed to access file");
} }
...@@ -137,7 +137,7 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8) ...@@ -137,7 +137,7 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8)
SMBCFILE *handle; SMBCFILE *handle;
{ {
const std::lock_guard<Mutex> protect(mutex); const std::scoped_lock<Mutex> protect(mutex);
handle = ctx.OpenDirectory(mapped.c_str()); handle = ctx.OpenDirectory(mapped.c_str());
} }
...@@ -158,14 +158,14 @@ SkipNameFS(PathTraitsFS::const_pointer name) noexcept ...@@ -158,14 +158,14 @@ SkipNameFS(PathTraitsFS::const_pointer name) noexcept
SmbclientDirectoryReader::~SmbclientDirectoryReader() SmbclientDirectoryReader::~SmbclientDirectoryReader()
{ {
const std::lock_guard<Mutex> lock(storage.mutex); const std::scoped_lock<Mutex> lock(storage.mutex);
storage.ctx.CloseDirectory(handle); storage.ctx.CloseDirectory(handle);
} }
const char * const char *
SmbclientDirectoryReader::Read() noexcept SmbclientDirectoryReader::Read() noexcept
{ {
const std::lock_guard<Mutex> protect(storage.mutex); const std::scoped_lock<Mutex> protect(storage.mutex);
while (auto e = storage.ctx.ReadDirectory(handle)) { while (auto e = storage.ctx.ReadDirectory(handle)) {
name = e->name; name = e->name;
......
...@@ -159,7 +159,7 @@ UdisksStorage::SetMountPoint(Path mount_point) ...@@ -159,7 +159,7 @@ UdisksStorage::SetMountPoint(Path mount_point)
void void
UdisksStorage::LockSetMountPoint(Path mount_point) UdisksStorage::LockSetMountPoint(Path mount_point)
{ {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
SetMountPoint(mount_point); SetMountPoint(mount_point);
} }
...@@ -191,7 +191,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept ...@@ -191,7 +191,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
return; return;
} }
} catch (...) { } catch (...) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
...@@ -247,7 +247,7 @@ try { ...@@ -247,7 +247,7 @@ try {
mount_request.Send(connection, *msg.Get(), mount_request.Send(connection, *msg.Get(),
[this](auto o) { return OnMountNotify(std::move(o)); }); [this](auto o) { return OnMountNotify(std::move(o)); });
} catch (...) { } catch (...) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
...@@ -266,7 +266,7 @@ try { ...@@ -266,7 +266,7 @@ try {
const char *mount_path = i.GetString(); const char *mount_path = i.GetString();
LockSetMountPoint(Path::FromFS(mount_path)); LockSetMountPoint(Path::FromFS(mount_path));
} catch (...) { } catch (...) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
...@@ -304,7 +304,7 @@ try { ...@@ -304,7 +304,7 @@ try {
mount_request.Send(connection, *msg.Get(), mount_request.Send(connection, *msg.Get(),
[this](auto u) { return OnUnmountNotify(std::move(u)); }); [this](auto u) { return OnUnmountNotify(std::move(u)); });
} catch (...) { } catch (...) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = std::current_exception(); mount_error = std::current_exception();
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();
...@@ -316,12 +316,12 @@ try { ...@@ -316,12 +316,12 @@ try {
using namespace ODBus; using namespace ODBus;
reply.CheckThrowError(); reply.CheckThrowError();
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = {}; mount_error = {};
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();
} catch (...) { } catch (...) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
mount_error = std::current_exception(); mount_error = std::current_exception();
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();
......
...@@ -38,7 +38,7 @@ TagBuilder::TagBuilder(const Tag &other) noexcept ...@@ -38,7 +38,7 @@ TagBuilder::TagBuilder(const Tag &other) noexcept
const std::size_t n = other.num_items; const std::size_t n = other.num_items;
if (n > 0) { if (n > 0) {
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (std::size_t i = 0; i != n; ++i) for (std::size_t i = 0; i != n; ++i)
items.push_back(tag_pool_dup_item(other.items[i])); items.push_back(tag_pool_dup_item(other.items[i]));
} }
...@@ -72,7 +72,7 @@ TagBuilder::operator=(const TagBuilder &other) noexcept ...@@ -72,7 +72,7 @@ TagBuilder::operator=(const TagBuilder &other) noexcept
items = other.items; items = other.items;
/* increment the tag pool refcounters */ /* increment the tag pool refcounters */
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (auto &i : items) for (auto &i : items)
i = tag_pool_dup_item(i); i = tag_pool_dup_item(i);
} }
...@@ -188,7 +188,7 @@ TagBuilder::Complement(const Tag &other) noexcept ...@@ -188,7 +188,7 @@ TagBuilder::Complement(const Tag &other) noexcept
const std::size_t n = other.num_items; const std::size_t n = other.num_items;
if (n > 0) { if (n > 0) {
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (std::size_t i = 0; i != n; ++i) { for (std::size_t i = 0; i != n; ++i) {
TagItem *item = other.items[i]; TagItem *item = other.items[i];
if (!present[item->type]) if (!present[item->type])
...@@ -203,7 +203,7 @@ TagBuilder::AddItemUnchecked(TagType type, StringView value) noexcept ...@@ -203,7 +203,7 @@ TagBuilder::AddItemUnchecked(TagType type, StringView value) noexcept
TagItem *i; TagItem *i;
{ {
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
i = tag_pool_get_item(type, value); i = tag_pool_get_item(type, value);
} }
...@@ -252,7 +252,7 @@ TagBuilder::RemoveAll() noexcept ...@@ -252,7 +252,7 @@ TagBuilder::RemoveAll() noexcept
return; return;
{ {
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (auto i : items) for (auto i : items)
tag_pool_put_item(i); tag_pool_put_item(i);
} }
......
...@@ -30,7 +30,7 @@ Tag::Clear() noexcept ...@@ -30,7 +30,7 @@ Tag::Clear() noexcept
has_playlist = false; has_playlist = false;
{ {
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (unsigned i = 0; i < num_items; ++i) for (unsigned i = 0; i < num_items; ++i)
tag_pool_put_item(items[i]); tag_pool_put_item(items[i]);
} }
...@@ -47,7 +47,7 @@ Tag::Tag(const Tag &other) noexcept ...@@ -47,7 +47,7 @@ Tag::Tag(const Tag &other) noexcept
if (num_items > 0) { if (num_items > 0) {
items = new TagItem *[num_items]; items = new TagItem *[num_items];
const std::lock_guard<Mutex> protect(tag_pool_lock); const std::scoped_lock<Mutex> protect(tag_pool_lock);
for (unsigned i = 0; i < num_items; i++) for (unsigned i = 0; i < num_items; i++)
items[i] = tag_pool_dup_item(other.items[i]); items[i] = tag_pool_dup_item(other.items[i]);
} }
......
...@@ -38,7 +38,7 @@ class SafeSingleton { ...@@ -38,7 +38,7 @@ class SafeSingleton {
public: public:
template<typename... Args> template<typename... Args>
explicit SafeSingleton(Args&&... args) { explicit SafeSingleton(Args&&... args) {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
if (ref == 0) if (ref == 0)
instance = new T(std::forward<Args>(args)...); instance = new T(std::forward<Args>(args)...);
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
} }
~SafeSingleton() noexcept { ~SafeSingleton() noexcept {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
if (--ref > 0) if (--ref > 0)
return; return;
......
...@@ -68,7 +68,7 @@ dump_input_stream(InputStreamPtr &&is) ...@@ -68,7 +68,7 @@ dump_input_stream(InputStreamPtr &&is)
dump_text_file(tis); dump_text_file(tis);
} }
const std::lock_guard<Mutex> protect(is->mutex); const std::scoped_lock<Mutex> protect(is->mutex);
is->Check(); is->Check();
return 0; return 0;
......
...@@ -223,14 +223,14 @@ public: ...@@ -223,14 +223,14 @@ public:
/* virtual methods from RemoteTagHandler */ /* virtual methods from RemoteTagHandler */
void OnRemoteTag(Tag &&_tag) noexcept override { void OnRemoteTag(Tag &&_tag) noexcept override {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
tag = std::move(_tag); tag = std::move(_tag);
done = true; done = true;
cond.notify_all(); cond.notify_all();
} }
void OnRemoteTagError(std::exception_ptr e) noexcept override { void OnRemoteTagError(std::exception_ptr e) noexcept override {
const std::lock_guard<Mutex> lock(mutex); const std::scoped_lock<Mutex> lock(mutex);
error = std::move(e); error = std::move(e);
done = true; done = true;
cond.notify_all(); cond.notify_all();
......
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