*: use std::scoped_lock with implicit template parameter

This commit is contained in:
Max Kellermann 2024-05-23 20:43:31 +02:00
parent 4fc3230fe6
commit 381215fd73
68 changed files with 253 additions and 253 deletions

View File

@ -15,7 +15,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks)
MusicChunkPtr MusicChunkPtr
MusicBuffer::Allocate() noexcept MusicBuffer::Allocate() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return {buffer.Allocate(), MusicChunkDeleter(*this)}; return {buffer.Allocate(), MusicChunkDeleter(*this)};
} }
@ -30,7 +30,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept
chunk->next.reset(); chunk->next.reset();
chunk->other.reset(); chunk->other.reset();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(!chunk->other || !chunk->other->other); assert(!chunk->other || !chunk->other->other);

View File

@ -39,7 +39,7 @@ public:
#endif #endif
bool IsFull() const noexcept { bool IsFull() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return buffer.IsFull(); return buffer.IsFull();
} }

View File

@ -11,7 +11,7 @@
bool bool
MusicPipe::Contains(const MusicChunk *chunk) const noexcept MusicPipe::Contains(const MusicChunk *chunk) const noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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)
@ -25,7 +25,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept
MusicChunkPtr MusicChunkPtr
MusicPipe::Shift() noexcept MusicPipe::Shift() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
auto chunk = std::move(head); auto chunk = std::move(head);
if (chunk != nullptr) { if (chunk != nullptr) {
@ -65,7 +65,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(size > 0 || !audio_format.IsDefined()); assert(size > 0 || !audio_format.IsDefined());
assert(!audio_format.IsDefined() || assert(!audio_format.IsDefined() ||

View File

@ -61,7 +61,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
const MusicChunk *Peek() const noexcept { const MusicChunk *Peek() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return head.get(); return head.get();
} }
@ -85,7 +85,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
unsigned GetSize() const noexcept { unsigned GetSize() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return size; return size;
} }

View File

@ -26,7 +26,7 @@ RemoteTagCache::~RemoteTagCache() noexcept
void void
RemoteTagCache::Lookup(const std::string &uri) noexcept RemoteTagCache::Lookup(const std::string &uri) noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
auto [tag, value] = map.insert_check(uri); auto [tag, value] = map.insert_check(uri);
if (value) { if (value) {
@ -80,7 +80,7 @@ RemoteTagCache::ItemResolved(Item &item) noexcept
void void
RemoteTagCache::InvokeHandlers() noexcept RemoteTagCache::InvokeHandlers() noexcept
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
while (!invoke_list.empty()) { while (!invoke_list.empty()) {
auto &item = invoke_list.pop_front(); auto &item = invoke_list.pop_front();
@ -105,7 +105,7 @@ RemoteTagCache::Item::OnRemoteTag(Tag &&_tag) noexcept
scanner.reset(); scanner.reset();
const std::scoped_lock<Mutex> lock(parent.mutex); const std::scoped_lock lock{parent.mutex};
parent.ItemResolved(*this); parent.ItemResolved(*this);
} }
@ -117,6 +117,6 @@ RemoteTagCache::Item::OnRemoteTagError(std::exception_ptr e) noexcept
scanner.reset(); scanner.reset();
const std::scoped_lock<Mutex> lock(parent.mutex); const std::scoped_lock lock{parent.mutex};
parent.ItemResolved(*this); parent.ItemResolved(*this);
} }

View File

@ -195,7 +195,7 @@ read_stream_art(Response &r, const std::string_view art_directory,
std::size_t read_size = 0; std::size_t read_size = 0;
if (buffer_size > 0) { if (buffer_size > 0) {
std::unique_lock<Mutex> lock(is->mutex); std::unique_lock lock{is->mutex};
is->Seek(lock, offset); is->Seek(lock, offset);
read_size = is->Read(lock, {buffer.get(), buffer_size}); read_size = is->Read(lock, {buffer.get(), buffer_size});
} }

View File

@ -51,7 +51,7 @@ protected:
} }
void CancelThread() noexcept override { void CancelThread() noexcept override {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
cancel = true; cancel = true;
cond.notify_one(); cond.notify_one();
} }
@ -188,7 +188,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is,
return false; return false;
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (cancel) if (cancel)
throw StopDecoder(); throw StopDecoder();
} }
@ -257,7 +257,7 @@ GetChromaprintCommand::OpenUri(const char *uri2)
auto is = InputStream::Open(uri2, mutex); auto is = InputStream::Open(uri2, mutex);
is->SetHandler(this); is->SetHandler(this);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
if (cancel) if (cancel)
throw StopDecoder(); throw StopDecoder();
@ -282,7 +282,7 @@ GetChromaprintCommand::Read(InputStream &is,
if (dest.empty()) if (dest.empty())
return 0; return 0;
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
if (cancel) if (cancel)

View File

@ -20,7 +20,7 @@ UpdateRemoveService::RunDeferred() noexcept
std::forward_list<std::string> copy; std::forward_list<std::string> copy;
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
std::swap(uris, copy); std::swap(uris, copy);
} }
@ -39,7 +39,7 @@ UpdateRemoveService::Remove(std::string &&uri)
bool was_empty; bool was_empty;
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
was_empty = uris.empty(); was_empty = uris.empty();
uris.emplace_front(std::move(uri)); uris.emplace_front(std::move(uri));
} }

View File

@ -95,7 +95,7 @@ NeedChunks(DecoderControl &dc, std::unique_lock<Mutex> &lock) noexcept
static DecoderCommand static DecoderCommand
LockNeedChunks(DecoderControl &dc) noexcept LockNeedChunks(DecoderControl &dc) noexcept
{ {
std::unique_lock<Mutex> lock(dc.mutex); std::unique_lock lock{dc.mutex};
return NeedChunks(dc, lock); return NeedChunks(dc, lock);
} }
@ -135,7 +135,7 @@ DecoderBridge::FlushChunk() noexcept
if (!chunk->IsEmpty()) if (!chunk->IsEmpty())
dc.pipe->Push(std::move(chunk)); dc.pipe->Push(std::move(chunk));
const std::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock protect{dc.mutex};
dc.client_cond.notify_one(); dc.client_cond.notify_one();
} }
@ -197,7 +197,7 @@ DecoderBridge::GetVirtualCommand() noexcept
DecoderCommand DecoderCommand
DecoderBridge::LockGetVirtualCommand() noexcept DecoderBridge::LockGetVirtualCommand() noexcept
{ {
const std::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock protect{dc.mutex};
return GetVirtualCommand(); return GetVirtualCommand();
} }
@ -257,7 +257,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
seekable); seekable);
{ {
const std::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock protect{dc.mutex};
dc.SetReady(audio_format, seekable, duration); dc.SetReady(audio_format, seekable, duration);
} }
@ -283,7 +283,7 @@ DecoderBridge::GetCommand() noexcept
void void
DecoderBridge::CommandFinished() noexcept DecoderBridge::CommandFinished() noexcept
{ {
const std::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock 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 ||
@ -379,7 +379,7 @@ DecoderBridge::OpenUri(const char *uri)
auto is = InputStream::Open(uri, mutex); auto is = InputStream::Open(uri, mutex);
is->SetHandler(&dc); is->SetHandler(&dc);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
if (dc.command == DecoderCommand::STOP) if (dc.command == DecoderCommand::STOP)
throw StopDecoder(); throw StopDecoder();
@ -403,7 +403,7 @@ try {
if (dest.empty()) if (dest.empty())
return 0; return 0;
std::unique_lock<Mutex> lock(is.mutex); std::unique_lock lock{is.mutex};
while (true) { while (true) {
if (CheckCancelRead()) if (CheckCancelRead())

View File

@ -215,7 +215,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockIsIdle() const noexcept { bool LockIsIdle() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return IsIdle(); return IsIdle();
} }
@ -225,7 +225,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockIsStarting() const noexcept { bool LockIsStarting() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return IsStarting(); return IsStarting();
} }
@ -237,13 +237,13 @@ public:
[[gnu::pure]] [[gnu::pure]]
bool LockHasFailed() const noexcept { bool LockHasFailed() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return HasFailed(); return HasFailed();
} }
[[gnu::pure]] [[gnu::pure]]
bool LockIsReplayGainEnabled() const noexcept { bool LockIsReplayGainEnabled() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return replay_gain_mode != ReplayGainMode::OFF; return replay_gain_mode != ReplayGainMode::OFF;
} }
@ -274,7 +274,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
CheckRethrowError(); CheckRethrowError();
} }
@ -344,13 +344,13 @@ private:
* object. * object.
*/ */
void LockSynchronousCommand(DecoderCommand cmd) noexcept { void LockSynchronousCommand(DecoderCommand cmd) noexcept {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
ClearError(); ClearError();
SynchronousCommandLocked(lock, cmd); SynchronousCommandLocked(lock, cmd);
} }
void LockAsynchronousCommand(DecoderCommand cmd) noexcept { void LockAsynchronousCommand(DecoderCommand cmd) noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
command = cmd; command = cmd;
Signal(); Signal();
} }

View File

@ -272,7 +272,7 @@ TryUriDecode(DecoderBridge &bridge, const char *uri)
if (!plugin.SupportsUri(uri)) if (!plugin.SupportsUri(uri))
return false; return false;
std::unique_lock<Mutex> lock(bridge.dc.mutex); std::unique_lock lock{bridge.dc.mutex};
bridge.Reset(); bridge.Reset();
return DecoderUriDecode(plugin, bridge, uri); return DecoderUriDecode(plugin, bridge, uri);
}); });
@ -296,7 +296,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri)
MaybeLoadReplayGain(bridge, *input_stream); MaybeLoadReplayGain(bridge, *input_stream);
std::unique_lock<Mutex> lock(dc.mutex); std::unique_lock lock{dc.mutex};
bool tried = false; bool tried = false;
return dc.command == DecoderCommand::STOP || return dc.command == DecoderCommand::STOP ||
@ -326,10 +326,10 @@ 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::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock 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 lock{dc.mutex};
return decoder_stream_decode(plugin, bridge, input_stream, return decoder_stream_decode(plugin, bridge, input_stream,
lock); lock);
} else } else
@ -354,7 +354,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs,
bridge.Reset(); bridge.Reset();
DecoderControl &dc = bridge.dc; DecoderControl &dc = bridge.dc;
const std::scoped_lock<Mutex> protect(dc.mutex); const std::scoped_lock protect{dc.mutex};
return decoder_file_decode(plugin, bridge, path_fs); return decoder_file_decode(plugin, bridge, path_fs);
} }
@ -545,7 +545,7 @@ DecoderControl::RunThread() noexcept
{ {
SetThreadName("decoder"); SetThreadName("decoder");
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
do { do {
assert(state == DecoderState::STOP || assert(state == DecoderState::STOP ||

View File

@ -242,7 +242,7 @@ AsyncInputStream::AppendToBuffer(std::span<const std::byte> src) noexcept
void void
AsyncInputStream::DeferredResume() noexcept AsyncInputStream::DeferredResume() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
try { try {
Resume(); Resume();
@ -255,7 +255,7 @@ AsyncInputStream::DeferredResume() noexcept
void void
AsyncInputStream::DeferredSeek() noexcept AsyncInputStream::DeferredSeek() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (seek_state != SeekState::SCHEDULED) if (seek_state != SeekState::SCHEDULED)
return; return;

View File

@ -23,7 +23,7 @@ BufferingInputStream::BufferingInputStream(InputStreamPtr _input)
BufferingInputStream::~BufferingInputStream() noexcept BufferingInputStream::~BufferingInputStream() noexcept
{ {
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
stop = true; stop = true;
wake_cond.notify_one(); wake_cond.notify_one();
} }
@ -166,7 +166,7 @@ BufferingInputStream::RunThread() noexcept
{ {
SetThreadName("buffering"); SetThreadName("buffering");
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
try { try {
RunThreadLocked(lock); RunThreadLocked(lock);

View File

@ -61,14 +61,14 @@ InputStream::Seek(std::unique_lock<Mutex> &, [[maybe_unused]] offset_type new_of
void void
InputStream::LockSeek(offset_type _offset) InputStream::LockSeek(offset_type _offset)
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
Seek(lock, _offset); Seek(lock, _offset);
} }
void void
InputStream::LockSkip(offset_type _offset) InputStream::LockSkip(offset_type _offset)
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
Skip(lock, _offset); Skip(lock, _offset);
} }
@ -81,7 +81,7 @@ InputStream::ReadTag() noexcept
std::unique_ptr<Tag> std::unique_ptr<Tag>
InputStream::LockReadTag() noexcept InputStream::LockReadTag() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return ReadTag(); return ReadTag();
} }
@ -96,7 +96,7 @@ InputStream::LockRead(std::span<std::byte> dest)
{ {
assert(!dest.empty()); assert(!dest.empty());
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
return Read(lock, dest); return Read(lock, dest);
} }
@ -119,14 +119,14 @@ InputStream::LockReadFull(std::span<std::byte> dest)
{ {
assert(!dest.empty()); assert(!dest.empty());
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
ReadFull(lock, dest); ReadFull(lock, dest);
} }
bool bool
InputStream::LockIsEOF() const noexcept InputStream::LockIsEOF() const noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return IsEOF(); return IsEOF();
} }

View File

@ -289,7 +289,7 @@ public:
} }
void LockRewind() { void LockRewind() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
Rewind(lock); Rewind(lock);
} }

View File

@ -30,7 +30,7 @@ ThreadInputStream::Stop() noexcept
return; return;
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
close = true; close = true;
wake_cond.notify_one(); wake_cond.notify_one();
} }
@ -53,7 +53,7 @@ ThreadInputStream::ThreadFunc() noexcept
{ {
FmtThreadName("input:{}", plugin); FmtThreadName("input:{}", plugin);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
try { try {
Open(); Open();

View File

@ -21,14 +21,14 @@ InputCacheItem::~InputCacheItem() noexcept
void void
InputCacheItem::AddLease(InputCacheLease &lease) noexcept InputCacheItem::AddLease(InputCacheLease &lease) noexcept
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
leases.push_back(lease); leases.push_back(lease);
} }
void void
InputCacheItem::RemoveLease(InputCacheLease &lease) noexcept InputCacheItem::RemoveLease(InputCacheLease &lease) noexcept
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock 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;

View File

@ -43,7 +43,7 @@ public:
using BufferingInputStream::size; using BufferingInputStream::size;
bool IsInUse() const noexcept { bool IsInUse() const noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
return !leases.empty(); return !leases.empty();
} }

View File

@ -20,7 +20,7 @@ CacheInputStream::Check()
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const std::scoped_lock<Mutex> protect(i.mutex); const std::scoped_lock protect{i.mutex};
i.Check(); i.Check();
} }
@ -44,7 +44,7 @@ CacheInputStream::IsAvailable() const noexcept
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const std::scoped_lock<Mutex> protect(i.mutex); const std::scoped_lock protect{i.mutex};
return i.IsAvailable(_offset); return i.IsAvailable(_offset);
} }
@ -60,7 +60,7 @@ CacheInputStream::Read(std::unique_lock<Mutex> &lock,
{ {
const ScopeUnlock unlock(mutex); const ScopeUnlock unlock(mutex);
const std::scoped_lock<Mutex> protect(i.mutex); const std::scoped_lock protect{i.mutex};
nbytes = i.Read(lock, _offset, dest); nbytes = i.Read(lock, _offset, dest);
} }
@ -75,6 +75,6 @@ CacheInputStream::OnInputCacheAvailable() noexcept
auto &i = GetCacheItem(); auto &i = GetCacheItem();
const ScopeUnlock unlock(i.mutex); const ScopeUnlock unlock(i.mutex);
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
InvokeOnAvailable(); InvokeOnAvailable();
} }

View File

@ -222,7 +222,7 @@ AlsaInputStream::DispatchSockets() noexcept
try { try {
non_block.DispatchSockets(*this, capture_handle); non_block.DispatchSockets(*this, capture_handle);
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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;

View File

@ -266,7 +266,7 @@ CurlInputStream::OnHeaders(unsigned status,
FmtBuffer<40>("got HTTP status {}", FmtBuffer<40>("got HTTP status {}",
status).c_str()); status).c_str());
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (IsSeekPending()) { if (IsSeekPending()) {
/* don't update metadata while seeking */ /* don't update metadata while seeking */
@ -329,7 +329,7 @@ CurlInputStream::OnData(std::span<const std::byte> data)
{ {
assert(!data.empty()); assert(!data.empty());
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (IsSeekPending()) if (IsSeekPending())
SeekDone(); SeekDone();
@ -345,7 +345,7 @@ CurlInputStream::OnData(std::span<const std::byte> data)
void void
CurlInputStream::OnEnd() CurlInputStream::OnEnd()
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
InvokeOnAvailable(); InvokeOnAvailable();
AsyncInputStream::SetClosed(); AsyncInputStream::SetClosed();
@ -354,7 +354,7 @@ CurlInputStream::OnEnd()
void void
CurlInputStream::OnError(std::exception_ptr e) noexcept CurlInputStream::OnError(std::exception_ptr e) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
postponed_exception = std::move(e); postponed_exception = std::move(e);
if (IsSeekPending()) if (IsSeekPending())

View File

@ -138,7 +138,7 @@ NfsInputStream::DoSeek(offset_type new_offset)
void void
NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (reconnecting) { if (reconnecting) {
/* reconnect has succeeded */ /* reconnect has succeeded */
@ -158,7 +158,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size) noexcept
void void
NfsInputStream::OnNfsFileRead(std::span<const std::byte> src) noexcept NfsInputStream::OnNfsFileRead(std::span<const std::byte> src) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(!IsBufferFull()); assert(!IsBufferFull());
assert(IsBufferFull() == (GetBufferSpace() == 0)); assert(IsBufferFull() == (GetBufferSpace() == 0));
@ -172,7 +172,7 @@ NfsInputStream::OnNfsFileRead(std::span<const std::byte> src) noexcept
void void
NfsInputStream::OnNfsFileError(std::exception_ptr &&e) noexcept NfsInputStream::OnNfsFileError(std::exception_ptr &&e) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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

View File

@ -71,7 +71,7 @@ QobuzClient::StartLogin()
void void
QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(!h.is_linked()); assert(!h.is_linked());
const bool was_empty = handlers.empty(); const bool was_empty = handlers.empty();
@ -98,7 +98,7 @@ QobuzClient::AddLoginHandler(QobuzSessionHandler &h) noexcept
QobuzSession QobuzSession
QobuzClient::GetSession() const QobuzClient::GetSession() const
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
@ -113,7 +113,7 @@ void
QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept QobuzClient::OnQobuzLoginSuccess(QobuzSession &&_session) noexcept
{ {
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
session = std::move(_session); session = std::move(_session);
login_request.reset(); login_request.reset();
} }
@ -125,7 +125,7 @@ void
QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
{ {
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
error = std::move(_error); error = std::move(_error);
login_request.reset(); login_request.reset();
} }
@ -136,7 +136,7 @@ QobuzClient::OnQobuzLoginError(std::exception_ptr _error) noexcept
void void
QobuzClient::InvokeHandlers() noexcept QobuzClient::InvokeHandlers() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
while (!handlers.empty()) { while (!handlers.empty()) {
auto &h = handlers.front(); auto &h = handlers.front();
handlers.pop_front(); handlers.pop_front();

View File

@ -67,7 +67,7 @@ public:
void AddLoginHandler(QobuzSessionHandler &h) noexcept; void AddLoginHandler(QobuzSessionHandler &h) noexcept;
void RemoveLoginHandler(QobuzSessionHandler &h) noexcept { void RemoveLoginHandler(QobuzSessionHandler &h) noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (h.is_linked()) if (h.is_linked())
h.unlink(); h.unlink();
} }

View File

@ -68,7 +68,7 @@ private:
void void
QobuzInputStream::OnQobuzSession() noexcept QobuzInputStream::OnQobuzSession() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
try { try {
const auto session = qobuz_client->GetSession(); const auto session = qobuz_client->GetSession();
@ -87,7 +87,7 @@ QobuzInputStream::OnQobuzSession() noexcept
void void
QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept QobuzInputStream::OnQobuzTrackSuccess(std::string url) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
track_request.reset(); track_request.reset();
try { try {
@ -101,7 +101,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
track_request.reset(); track_request.reset();
Failed(e); Failed(e);

View File

@ -133,7 +133,7 @@ UringInputStream::OnRead(std::unique_ptr<std::byte[]> data,
{ {
read_operation.reset(); read_operation.reset();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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"));
@ -154,7 +154,7 @@ UringInputStream::OnReadError(int error) noexcept
{ {
read_operation.reset(); read_operation.reset();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
postponed_exception = std::make_exception_ptr(MakeErrno(error, "Read failed")); postponed_exception = std::make_exception_ptr(MakeErrno(error, "Read failed"));
InvokeOnAvailable(); InvokeOnAvailable();

View File

@ -92,7 +92,7 @@ AllocatedString
IcuConverter::ToUTF8(std::string_view s) const IcuConverter::ToUTF8(std::string_view s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
ucnv_resetToUnicode(converter); ucnv_resetToUnicode(converter);
@ -119,7 +119,7 @@ AllocatedString
IcuConverter::FromUTF8(std::string_view s) const IcuConverter::FromUTF8(std::string_view s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
const auto u = UCharFromUTF8(s); const auto u = UCharFromUTF8(s);

View File

@ -43,7 +43,7 @@ public:
private: private:
bool LockWaitFinished() noexcept { bool LockWaitFinished() noexcept {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
return cond.wait_for(lock, timeout, [this]{ return finished; }); return cond.wait_for(lock, timeout, [this]{ return finished; });
} }
@ -52,7 +52,7 @@ private:
* thread. * thread.
*/ */
void LockSetFinished() noexcept { void LockSetFinished() noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
finished = true; finished = true;
cond.notify_one(); cond.notify_one();
} }

View File

@ -29,7 +29,7 @@ SmbclientContext::New()
SMBCCTX *ctx; SMBCCTX *ctx;
{ {
const std::scoped_lock<Mutex> protect(global_mutex); const std::scoped_lock protect{global_mutex};
ctx = smbc_new_context(); ctx = smbc_new_context();
} }

View File

@ -32,7 +32,7 @@ public:
~SmbclientContext() noexcept { ~SmbclientContext() noexcept {
if (ctx != nullptr) { if (ctx != nullptr) {
const std::scoped_lock<Mutex> protect(global_mutex); const std::scoped_lock protect{global_mutex};
smbc_free_context(ctx, 1); smbc_free_context(ctx, 1);
} }
} }

View File

@ -45,7 +45,7 @@ UpnpClientGlobalInit(const char* iface)
UpnpGlobalInit(iface); UpnpGlobalInit(iface);
try { try {
const std::scoped_lock<Mutex> protect(upnp_client_init_mutex); const std::scoped_lock protect{upnp_client_init_mutex};
if (upnp_client_ref == 0) if (upnp_client_ref == 0)
DoInit(); DoInit();
} catch (...) { } catch (...) {
@ -61,7 +61,7 @@ void
UpnpClientGlobalFinish() noexcept UpnpClientGlobalFinish() noexcept
{ {
{ {
const std::scoped_lock<Mutex> protect(upnp_client_init_mutex); const std::scoped_lock 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)

View File

@ -88,14 +88,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::scoped_lock<Mutex> protect(parent.mutex); const std::scoped_lock 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::scoped_lock<Mutex> protect(parent.mutex); const std::scoped_lock protect{parent.mutex};
unlink(); unlink();
delete this; delete this;
} }
@ -189,7 +189,7 @@ AnnounceLostUPnP(UPnPDiscoveryListener &listener, const UPnPDevice &device) noex
inline void inline void
UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d) noexcept UPnPDeviceDirectory::LockAdd(std::string &&id, ContentDirectoryDescriptor &&d) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
const auto i = directories.insert_or_assign(std::move(id), std::move(d)).first; 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 inline void
UPnPDeviceDirectory::LockRemove(const std::string_view id) noexcept UPnPDeviceDirectory::LockRemove(const std::string_view id) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (auto i = directories.find(id); i != directories.end()) { if (auto i = directories.find(id); i != directories.end()) {
if (listener != nullptr) if (listener != nullptr)
@ -297,7 +297,7 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(EventLoop &event_loop,
UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept UPnPDeviceDirectory::~UPnPDeviceDirectory() noexcept
{ {
BlockingCall(GetEventLoop(), [this]() { BlockingCall(GetEventLoop(), [this]() {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
downloaders.clear_and_dispose(DeleteDisposer()); downloaders.clear_and_dispose(DeleteDisposer());
}); });
} }
@ -337,7 +337,7 @@ UPnPDeviceDirectory::Search()
std::vector<ContentDirectoryService> std::vector<ContentDirectoryService>
UPnPDeviceDirectory::GetDirectories() noexcept UPnPDeviceDirectory::GetDirectories() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
ExpireDevices(); ExpireDevices();
@ -356,7 +356,7 @@ UPnPDeviceDirectory::GetDirectories() noexcept
ContentDirectoryService ContentDirectoryService
UPnPDeviceDirectory::GetServer(std::string_view friendly_name) UPnPDeviceDirectory::GetServer(std::string_view friendly_name)
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
ExpireDevices(); ExpireDevices();

View File

@ -33,7 +33,7 @@ DoInit(const char* iface)
void void
UpnpGlobalInit(const char* iface) UpnpGlobalInit(const char* iface)
{ {
const std::scoped_lock<Mutex> protect(upnp_init_mutex); const std::scoped_lock protect{upnp_init_mutex};
if (upnp_ref == 0) if (upnp_ref == 0)
DoInit(iface); DoInit(iface);
@ -44,7 +44,7 @@ UpnpGlobalInit(const char* iface)
void void
UpnpGlobalFinish() noexcept UpnpGlobalFinish() noexcept
{ {
const std::scoped_lock<Mutex> protect(upnp_init_mutex); const std::scoped_lock protect{upnp_init_mutex};
assert(upnp_ref > 0); assert(upnp_ref > 0);

View File

@ -83,7 +83,7 @@ void
SmbclientNeighborExplorer::Close() noexcept SmbclientNeighborExplorer::Close() noexcept
{ {
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
quit = true; quit = true;
cond.notify_one(); cond.notify_one();
} }
@ -94,7 +94,7 @@ SmbclientNeighborExplorer::Close() noexcept
NeighborExplorer::List NeighborExplorer::List
SmbclientNeighborExplorer::GetList() const noexcept SmbclientNeighborExplorer::GetList() const noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return list; return list;
} }
@ -224,7 +224,7 @@ SmbclientNeighborExplorer::ThreadFunc() noexcept
{ {
SetThreadName("smbclient"); SetThreadName("smbclient");
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (!quit) { while (!quit) {
Run(); Run();

View File

@ -159,7 +159,7 @@ UdisksNeighborExplorer::Close() noexcept
NeighborExplorer::List NeighborExplorer::List
UdisksNeighborExplorer::GetList() const noexcept UdisksNeighborExplorer::GetList() const noexcept
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
NeighborExplorer::List result; NeighborExplorer::List result;
@ -176,7 +176,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept
const NeighborInfo info = ToNeighborInfo(o); const NeighborInfo info = ToNeighborInfo(o);
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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;
@ -191,7 +191,7 @@ UdisksNeighborExplorer::Insert(UDisks2::Object &&o) noexcept
void void
UdisksNeighborExplorer::Remove(const std::string &path) noexcept UdisksNeighborExplorer::Remove(const std::string &path) noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
auto i = by_path.find(path); auto i = by_path.find(path);
if (i == by_path.end()) if (i == by_path.end())

View File

@ -54,7 +54,7 @@ AudioOutputControl::Steal() noexcept
/* close and disable the output */ /* close and disable the output */
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (really_enabled && output->SupportsEnableDisable()) if (really_enabled && output->SupportsEnableDisable())
CommandWait(lock, Command::DISABLE); CommandWait(lock, Command::DISABLE);
@ -65,7 +65,7 @@ AudioOutputControl::Steal() noexcept
StopThread(); StopThread();
/* now we can finally remove it */ /* now we can finally remove it */
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return std::exchange(output, nullptr); return std::exchange(output, nullptr);
} }
@ -77,7 +77,7 @@ AudioOutputControl::ReplaceDummy(std::unique_ptr<FilteredAudioOutput> new_output
assert(new_output); assert(new_output);
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
output = std::move(new_output); output = std::move(new_output);
enabled = _enabled; enabled = _enabled;
} }
@ -126,7 +126,7 @@ AudioOutputControl::SetAttribute(std::string &&attribute_name,
bool bool
AudioOutputControl::LockSetEnabled(bool new_value) noexcept AudioOutputControl::LockSetEnabled(bool new_value) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (new_value == enabled) if (new_value == enabled)
return false; return false;
@ -138,7 +138,7 @@ AudioOutputControl::LockSetEnabled(bool new_value) noexcept
bool bool
AudioOutputControl::LockToggleEnabled() noexcept AudioOutputControl::LockToggleEnabled() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return enabled = !enabled; return enabled = !enabled;
} }
@ -168,7 +168,7 @@ AudioOutputControl::CommandWait(std::unique_lock<Mutex> &lock,
void void
AudioOutputControl::LockCommandWait(Command cmd) noexcept AudioOutputControl::LockCommandWait(Command cmd) noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
CommandWait(lock, cmd); CommandWait(lock, cmd);
} }
@ -300,7 +300,7 @@ AudioOutputControl::LockUpdate(const AudioFormat audio_format,
const MusicPipe &mp, const MusicPipe &mp,
bool force) noexcept bool force) noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (enabled && really_enabled) { if (enabled && really_enabled) {
if (force || !fail_timer.IsDefined() || if (force || !fail_timer.IsDefined() ||
@ -325,14 +325,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return IsChunkConsumed(chunk); return IsChunkConsumed(chunk);
} }
void void
AudioOutputControl::LockPlay() noexcept AudioOutputControl::LockPlay() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(allow_play); assert(allow_play);
@ -354,7 +354,7 @@ AudioOutputControl::LockPauseAsync() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
@ -364,7 +364,7 @@ AudioOutputControl::LockPauseAsync() noexcept
void void
AudioOutputControl::LockDrainAsync() noexcept AudioOutputControl::LockDrainAsync() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
@ -377,7 +377,7 @@ AudioOutputControl::LockCancelAsync() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (IsOpen()) { if (IsOpen()) {
allow_play = false; allow_play = false;
@ -388,7 +388,7 @@ AudioOutputControl::LockCancelAsync() noexcept
void void
AudioOutputControl::LockAllowPlay() noexcept AudioOutputControl::LockAllowPlay() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
allow_play = true; allow_play = true;
if (IsOpen()) if (IsOpen())
@ -410,7 +410,7 @@ AudioOutputControl::LockRelease() noexcept
Mixer::LockAutoClose()) */ Mixer::LockAutoClose()) */
output->mixer->LockAutoClose(); output->mixer->LockAutoClose();
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
assert(!open || !fail_timer.IsDefined()); assert(!open || !fail_timer.IsDefined());
assert(allow_play); assert(allow_play);
@ -429,7 +429,7 @@ AudioOutputControl::LockCloseWait() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
CloseWait(lock); CloseWait(lock);
} }
@ -440,7 +440,7 @@ AudioOutputControl::BeginDestroy() noexcept
if (output) if (output)
output->Interrupt(); output->Interrupt();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (!killed) { if (!killed) {
killed = true; killed = true;
CommandAsync(Command::KILL); CommandAsync(Command::KILL);

View File

@ -355,7 +355,7 @@ public:
void WaitForCommand(std::unique_lock<Mutex> &lock) noexcept; void WaitForCommand(std::unique_lock<Mutex> &lock) noexcept;
void LockWaitForCommand() noexcept { void LockWaitForCommand() noexcept {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
WaitForCommand(lock); WaitForCommand(lock);
} }
@ -407,7 +407,7 @@ public:
void EnableDisableAsync(); void EnableDisableAsync();
void LockEnableDisableAsync() { void LockEnableDisableAsync() {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
EnableDisableAsync(); EnableDisableAsync();
} }
@ -482,7 +482,7 @@ public:
* Locking wrapper for ClearTailChunk(). * Locking wrapper for ClearTailChunk().
*/ */
void LockClearTailChunk(const MusicChunk &chunk) noexcept { void LockClearTailChunk(const MusicChunk &chunk) noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
ClearTailChunk(chunk); ClearTailChunk(chunk);
} }

View File

@ -213,7 +213,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::scoped_lock<Mutex> lock(ao->mutex); const std::scoped_lock lock{ao->mutex};
/* can't play on this device even if it's enabled */ /* can't play on this device even if it's enabled */
if (ao->AlwaysOff()) if (ao->AlwaysOff())

View File

@ -27,7 +27,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::scoped_lock<Mutex> lock(ao.mutex); const std::scoped_lock lock{ao.mutex};
os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"), os.Fmt(FMT_STRING(AUDIO_DEVICE_STATE "{}:{}\n"),
(unsigned)ao.IsEnabled(), ao.GetName()); (unsigned)ao.IsEnabled(), ao.GetName());

View File

@ -417,7 +417,7 @@ AudioOutputControl::Task() noexcept
SetThreadTimerSlack(std::chrono::microseconds(100)); SetThreadTimerSlack(std::chrono::microseconds(100));
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
switch (command) { switch (command) {

View File

@ -294,13 +294,13 @@ private:
[[gnu::pure]] [[gnu::pure]]
bool LockIsActive() const noexcept { bool LockIsActive() const noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
return active; return active;
} }
[[gnu::pure]] [[gnu::pure]]
bool LockIsActiveAndNotWaiting() const noexcept { bool LockIsActiveAndNotWaiting() const noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
return active && !waiting; return active && !waiting;
} }
@ -366,7 +366,7 @@ private:
void LockCaughtError() noexcept { void LockCaughtError() noexcept {
period_buffer.Clear(); period_buffer.Clear();
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
error = std::current_exception(); error = std::current_exception();
active = false; active = false;
waiting = false; waiting = false;
@ -381,7 +381,7 @@ private:
*/ */
void OnSilenceTimer() noexcept { void OnSilenceTimer() noexcept {
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
assert(active); assert(active);
waiting = false; waiting = false;
} }
@ -447,7 +447,7 @@ AlsaOutput::AlsaOutput(EventLoop &_loop, const ConfigBlock &block)
std::map<std::string, std::string, std::less<>> std::map<std::string, std::string, std::less<>>
AlsaOutput::GetAttributes() const noexcept AlsaOutput::GetAttributes() const noexcept
{ {
const std::scoped_lock<Mutex> lock(attributes_mutex); const std::scoped_lock lock{attributes_mutex};
return { return {
{"allowed_formats", Alsa::ToString(allowed_formats)}, {"allowed_formats", Alsa::ToString(allowed_formats)},
@ -461,11 +461,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::scoped_lock<Mutex> lock(attributes_mutex); const std::scoped_lock 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::scoped_lock<Mutex> lock(attributes_mutex); const std::scoped_lock lock{attributes_mutex};
if (value == "0") if (value == "0")
dop_setting = false; dop_setting = false;
else if (value == "1") else if (value == "1")
@ -773,7 +773,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
#endif #endif
{ {
const std::scoped_lock<Mutex> lock(attributes_mutex); const std::scoped_lock lock{attributes_mutex};
#ifdef ENABLE_DSD #ifdef ENABLE_DSD
dop = dop_setting; dop = dop_setting;
#endif #endif
@ -877,7 +877,7 @@ AlsaOutput::Open(AudioFormat &audio_format)
void void
AlsaOutput::Interrupt() noexcept AlsaOutput::Interrupt() noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::scoped_lock lock{mutex};
/* the "interrupted" flag will prevent /* the "interrupted" flag will prevent
LockWaitWriteAvailable() from actually waiting, and will LockWaitWriteAvailable() from actually waiting, and will
@ -951,7 +951,7 @@ AlsaOutput::CopyRingToPeriodBuffer() noexcept
period_buffer.AppendBytes(nbytes); period_buffer.AppendBytes(nbytes);
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock 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();
@ -1069,7 +1069,7 @@ AlsaOutput::DrainInternal()
void void
AlsaOutput::Drain() AlsaOutput::Drain()
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
@ -1110,7 +1110,7 @@ void
AlsaOutput::Cancel() noexcept AlsaOutput::Cancel() noexcept
{ {
{ {
std::unique_lock<Mutex> lock(mutex); std::lock_guard lock{mutex};
interrupted = false; interrupted = false;
} }
@ -1128,7 +1128,7 @@ AlsaOutput::Cancel() noexcept
#ifdef ENABLE_DSD #ifdef ENABLE_DSD
if (stop_dsd_silence && use_dsd) { if (stop_dsd_silence && use_dsd) {
/* play some DSD silence instead of snd_pcm_drop() */ /* play some DSD silence instead of snd_pcm_drop() */
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
in_stop_dsd_silence = true; in_stop_dsd_silence = true;
drain = true; drain = true;
cond.wait(lock, [this]{ return !drain || !active; }); cond.wait(lock, [this]{ return !drain || !active; });
@ -1144,7 +1144,7 @@ AlsaOutput::Cancel() noexcept
bool bool
AlsaOutput::Pause() noexcept AlsaOutput::Pause() noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::lock_guard lock{mutex};
interrupted = false; interrupted = false;
/* not implemented - this override exists only to reset the /* 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 out_block_size = pcm_export->GetOutputBlockSize();
const size_t min_available = 2 * out_block_size; const size_t min_available = 2 * out_block_size;
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
if (error) if (error)
@ -1265,7 +1265,7 @@ try {
} }
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
assert(active); assert(active);
@ -1305,7 +1305,7 @@ try {
smaller than the ALSA-PCM buffer */ smaller than the ALSA-PCM buffer */
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
waiting = true; waiting = true;
cond.notify_one(); cond.notify_one();
} }

View File

@ -102,7 +102,7 @@ private:
void Disconnect() noexcept; void Disconnect() noexcept;
void Shutdown(const char *reason) noexcept { void Shutdown(const char *reason) noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
error = std::make_exception_ptr(FmtRuntimeError("JACK connection shutdown: {}", error = std::make_exception_ptr(FmtRuntimeError("JACK connection shutdown: {}",
reason)); reason));
} }
@ -166,7 +166,7 @@ public:
private: private:
bool LockWasShutdown() const noexcept { bool LockWasShutdown() const noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
return !!error; return !!error;
} }
}; };
@ -618,7 +618,7 @@ JackOutput::Open(AudioFormat &new_audio_format)
void void
JackOutput::Interrupt() noexcept JackOutput::Interrupt() noexcept
{ {
const std::unique_lock<Mutex> lock(mutex); const std::lock_guard lock{mutex};
/* the "interrupted" flag will prevent Play() from waiting, /* the "interrupted" flag will prevent Play() from waiting,
and will instead throw AudioOutputInterrupted */ and will instead throw AudioOutputInterrupted */
@ -680,7 +680,7 @@ JackOutput::Play(std::span<const std::byte> _src)
while (true) { while (true) {
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);
@ -702,7 +702,7 @@ JackOutput::Play(std::span<const std::byte> _src)
void void
JackOutput::Cancel() noexcept JackOutput::Cancel() noexcept
{ {
const std::unique_lock<Mutex> lock(mutex); const std::lock_guard lock{mutex};
interrupted = false; interrupted = false;
} }
@ -710,7 +710,7 @@ inline bool
JackOutput::Pause() JackOutput::Pause()
{ {
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
interrupted = false; interrupted = false;
if (error) if (error)
std::rethrow_exception(error); std::rethrow_exception(error);

View File

@ -34,7 +34,7 @@ HttpdClient::Close() noexcept
void void
HttpdClient::LockClose() noexcept HttpdClient::LockClose() noexcept
{ {
const std::scoped_lock<Mutex> protect(httpd.mutex); const std::scoped_lock protect{httpd.mutex};
Close(); Close();
} }
@ -224,7 +224,7 @@ HttpdClient::GetBytesTillMetaData() const noexcept
inline bool inline bool
HttpdClient::TryWrite() noexcept HttpdClient::TryWrite() noexcept
{ {
const std::scoped_lock<Mutex> protect(httpd.mutex); const std::scoped_lock protect{httpd.mutex};
assert(state == State::RESPONSE); assert(state == State::RESPONSE);

View File

@ -182,7 +182,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
bool LockHasClients() const noexcept { bool LockHasClients() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return HasClients(); return HasClients();
} }

View File

@ -96,7 +96,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
while (!pages.empty()) { while (!pages.empty()) {
PagePtr page = std::move(pages.front()); PagePtr page = std::move(pages.front());
@ -118,7 +118,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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))
@ -197,7 +197,7 @@ HttpdOutput::Open(AudioFormat &audio_format)
assert(!open); assert(!open);
assert(clients.empty()); assert(clients.empty());
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
OpenEncoder(audio_format); OpenEncoder(audio_format);
@ -219,7 +219,7 @@ HttpdOutput::Close() noexcept
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this](){
defer_broadcast.Cancel(); defer_broadcast.Cancel();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
open = false; open = false;
clients.clear_and_dispose(DeleteDisposer()); clients.clear_and_dispose(DeleteDisposer());
}); });
@ -272,7 +272,7 @@ HttpdOutput::BroadcastPage(PagePtr page) noexcept
assert(page != nullptr); assert(page != nullptr);
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
pages.emplace(std::move(page)); pages.emplace(std::move(page));
} }
@ -284,7 +284,7 @@ HttpdOutput::BroadcastFromEncoder() noexcept
{ {
/* synchronize with the IOThread */ /* synchronize with the IOThread */
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
cond.wait(lock, [this]{ return pages.empty(); }); cond.wait(lock, [this]{ return pages.empty(); });
} }
@ -292,7 +292,7 @@ HttpdOutput::BroadcastFromEncoder() noexcept
PagePtr page; PagePtr page;
while ((page = ReadPage()) != nullptr) { while ((page = ReadPage()) != nullptr) {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
pages.emplace(std::move(page)); pages.emplace(std::move(page));
empty = false; empty = false;
} }
@ -384,7 +384,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
for (auto &client : clients) for (auto &client : clients)
client.PushMetaData(metadata); client.PushMetaData(metadata);
} }
@ -394,7 +394,7 @@ HttpdOutput::SendTag(const Tag &tag)
inline void inline void
HttpdOutput::CancelAllClients() noexcept HttpdOutput::CancelAllClients() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
while (!pages.empty()) { while (!pages.empty()) {
PagePtr page = std::move(pages.front()); PagePtr page = std::move(pages.front());

View File

@ -330,7 +330,7 @@ SlesOutput::Play(std::span<const std::byte> src)
pause = false; pause = false;
} }
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
@ -360,7 +360,7 @@ SlesOutput::Play(std::span<const std::byte> src)
void void
SlesOutput::Drain() SlesOutput::Drain()
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
@ -382,7 +382,7 @@ SlesOutput::Cancel() noexcept
LogWarning(sles_domain, LogWarning(sles_domain,
"AndroidSimpleBufferQueue.Clear() failed"); "AndroidSimpleBufferQueue.Clear() failed");
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
n_queued = 0; n_queued = 0;
filled = 0; filled = 0;
} }
@ -407,7 +407,7 @@ SlesOutput::Pause()
inline void inline void
SlesOutput::PlayedCallback() SlesOutput::PlayedCallback()
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
assert(n_queued > 0); assert(n_queued > 0);
--n_queued; --n_queued;
cond.notify_one(); cond.notify_one();

View File

@ -40,7 +40,7 @@ SnapcastClient::Close() noexcept
void void
SnapcastClient::LockClose() noexcept SnapcastClient::LockClose() noexcept
{ {
const std::scoped_lock<Mutex> protect(output.mutex); const std::scoped_lock protect{output.mutex};
Close(); Close();
} }
@ -57,7 +57,7 @@ SnapcastClient::Push(SnapcastChunkPtr chunk) noexcept
SnapcastChunkPtr SnapcastChunkPtr
SnapcastClient::LockPopQueue() noexcept SnapcastClient::LockPopQueue() noexcept
{ {
const std::scoped_lock<Mutex> protect(output.mutex); const std::scoped_lock protect{output.mutex};
if (chunks.empty()) if (chunks.empty())
return nullptr; return nullptr;

View File

@ -118,7 +118,7 @@ public:
*/ */
[[gnu::pure]] [[gnu::pure]]
bool LockHasClients() const noexcept { bool LockHasClients() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return HasClients(); return HasClients();
} }

View File

@ -100,7 +100,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
/* can we allow additional client */ /* can we allow additional client */
if (open) if (open)
@ -130,7 +130,7 @@ SnapcastOutput::Open(AudioFormat &audio_format)
assert(!open); assert(!open);
assert(clients.empty()); assert(clients.empty());
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
OpenEncoder(audio_format); OpenEncoder(audio_format);
@ -152,7 +152,7 @@ SnapcastOutput::Close() noexcept
BlockingCall(GetEventLoop(), [this](){ BlockingCall(GetEventLoop(), [this](){
inject_event.Cancel(); inject_event.Cancel();
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
open = false; open = false;
clients.clear_and_dispose(DeleteDisposer{}); clients.clear_and_dispose(DeleteDisposer{});
}); });
@ -166,7 +166,7 @@ SnapcastOutput::Close() noexcept
void void
SnapcastOutput::OnInject() noexcept SnapcastOutput::OnInject() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
while (!chunks.empty()) { while (!chunks.empty()) {
const auto chunk = std::move(chunks.front()); 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 auto payload = std::as_bytes(std::span{json});
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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); client.SendStreamTags(payload);
@ -320,7 +320,7 @@ SnapcastOutput::Play(std::span<const std::byte> src)
unflushed_input = 0; unflushed_input = 0;
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (chunks.empty()) if (chunks.empty())
inject_event.Schedule(); inject_event.Schedule();
@ -350,14 +350,14 @@ SnapcastOutput::IsDrained() const noexcept
void void
SnapcastOutput::Drain() SnapcastOutput::Drain()
{ {
std::unique_lock<Mutex> protect(mutex); std::unique_lock protect{mutex};
drain_cond.wait(protect, [this]{ return IsDrained(); }); drain_cond.wait(protect, [this]{ return IsDrained(); });
} }
void void
SnapcastOutput::Cancel() noexcept SnapcastOutput::Cancel() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
ClearQueue(chunks); ClearQueue(chunks);

View File

@ -47,7 +47,7 @@ PlayerControl::Play(std::unique_ptr<DetachedSong> song)
assert(song != nullptr); assert(song != nullptr);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
SeekLocked(lock, std::move(song), SongTime::zero()); SeekLocked(lock, std::move(song), SongTime::zero());
if (state == PlayerState::PAUSE) if (state == PlayerState::PAUSE)
@ -110,7 +110,7 @@ PlayerControl::PauseLocked(std::unique_lock<Mutex> &lock) noexcept
void void
PlayerControl::LockPause() noexcept PlayerControl::LockPause() noexcept
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
PauseLocked(lock); PauseLocked(lock);
} }
@ -120,7 +120,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept
if (!thread.IsDefined()) if (!thread.IsDefined())
return; return;
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
switch (state) { switch (state) {
case PlayerState::STOP: case PlayerState::STOP:
@ -141,7 +141,7 @@ PlayerControl::LockSetPause(bool pause_flag) noexcept
void void
PlayerControl::LockSetBorderPause(bool _border_pause) noexcept PlayerControl::LockSetBorderPause(bool _border_pause) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
border_pause = _border_pause; border_pause = _border_pause;
} }
@ -150,7 +150,7 @@ PlayerControl::LockGetStatus() noexcept
{ {
PlayerStatus status; PlayerStatus status;
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (!occupied && thread.IsDefined()) if (!occupied && thread.IsDefined())
SynchronousCommand(lock, PlayerCommand::REFRESH); SynchronousCommand(lock, PlayerCommand::REFRESH);
@ -182,14 +182,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error) noexcept
void void
PlayerControl::LockClearError() noexcept PlayerControl::LockClearError() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
ClearError(); ClearError();
} }
void void
PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept PlayerControl::LockSetTaggedSong(const DetachedSong &song) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
tagged_song.reset(); tagged_song.reset();
tagged_song = std::make_unique<DetachedSong>(song); tagged_song = std::make_unique<DetachedSong>(song);
} }
@ -209,7 +209,7 @@ PlayerControl::ReadTaggedSong() noexcept
std::unique_ptr<DetachedSong> std::unique_ptr<DetachedSong>
PlayerControl::LockReadTaggedSong() noexcept PlayerControl::LockReadTaggedSong() noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return ReadTaggedSong(); return ReadTaggedSong();
} }
@ -219,7 +219,7 @@ PlayerControl::LockEnqueueSong(std::unique_ptr<DetachedSong> song) noexcept
assert(thread.IsDefined()); assert(thread.IsDefined());
assert(song != nullptr); assert(song != nullptr);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
EnqueueSongLocked(lock, std::move(song)); EnqueueSongLocked(lock, std::move(song));
} }
@ -278,7 +278,7 @@ PlayerControl::LockSeek(std::unique_ptr<DetachedSong> song, SongTime t)
assert(song != nullptr); assert(song != nullptr);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
SeekLocked(lock, std::move(song), t); SeekLocked(lock, std::move(song), t);
} }

View File

@ -224,7 +224,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
CheckRethrowError(); CheckRethrowError();
} }
@ -293,7 +293,7 @@ public:
} }
void LockSetReplayGainMode(ReplayGainMode _mode) noexcept { void LockSetReplayGainMode(ReplayGainMode _mode) noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
replay_gain_mode = _mode; replay_gain_mode = _mode;
} }
@ -316,7 +316,7 @@ public:
[[gnu::pure]] [[gnu::pure]]
SyncInfo LockGetSyncInfo() const noexcept { SyncInfo LockGetSyncInfo() const noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return {state, next_song != nullptr}; return {state, next_song != nullptr};
} }
@ -338,7 +338,7 @@ private:
* this function. * this function.
*/ */
void LockSignal() noexcept { void LockSignal() noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
Signal(); Signal();
} }
@ -391,7 +391,7 @@ private:
} }
void LockCommandFinished() noexcept { void LockCommandFinished() noexcept {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
CommandFinished(); CommandFinished();
} }
@ -409,7 +409,7 @@ private:
unsigned threshold) noexcept; unsigned threshold) noexcept;
bool LockWaitOutputConsumed(unsigned threshold) noexcept { bool LockWaitOutputConsumed(unsigned threshold) noexcept {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
return WaitOutputConsumed(lock, threshold); return WaitOutputConsumed(lock, threshold);
} }
@ -448,7 +448,7 @@ private:
* object. * object.
*/ */
void LockSynchronousCommand(PlayerCommand cmd) noexcept { void LockSynchronousCommand(PlayerCommand cmd) noexcept {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
SynchronousCommand(lock, cmd); SynchronousCommand(lock, cmd);
} }
@ -486,7 +486,7 @@ private:
} }
void LockSetOutputError(std::exception_ptr &&_error) noexcept { void LockSetOutputError(std::exception_ptr &&_error) noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
SetOutputError(std::move(_error)); SetOutputError(std::move(_error));
} }

View File

@ -923,7 +923,7 @@ PlayerControl::PlayChunk(DetachedSong &song, MusicChunkPtr chunk,
return; return;
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
bit_rate = chunk->bit_rate; bit_rate = chunk->bit_rate;
} }
@ -997,7 +997,7 @@ Player::PlayNextChunk() noexcept
} else { } else {
/* there are not enough decoded chunks yet */ /* there are not enough decoded chunks yet */
std::unique_lock<Mutex> lock(pc.mutex); std::unique_lock lock{pc.mutex};
if (dc.IsIdle()) { if (dc.IsIdle()) {
/* the decoder isn't running, abort /* the decoder isn't running, abort
@ -1045,7 +1045,7 @@ Player::PlayNextChunk() noexcept
return false; return false;
} }
const std::scoped_lock<Mutex> lock(pc.mutex); const std::scoped_lock 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
@ -1096,7 +1096,7 @@ Player::Run() noexcept
{ {
pipe = std::make_shared<MusicPipe>(); pipe = std::make_shared<MusicPipe>();
std::unique_lock<Mutex> lock(pc.mutex); std::unique_lock lock{pc.mutex};
StartDecoder(lock, pipe, true); StartDecoder(lock, pipe, true);
ActivateDecoder(); ActivateDecoder();
@ -1248,7 +1248,7 @@ try {
MusicBuffer buffer{config.buffer_chunks}; MusicBuffer buffer{config.buffer_chunks};
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
switch (command) { switch (command) {

View File

@ -179,7 +179,7 @@ CompositeStorage::~CompositeStorage() = default;
Storage * Storage *
CompositeStorage::GetMount(std::string_view uri) noexcept CompositeStorage::GetMount(std::string_view uri) noexcept
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
auto result = FindStorage(uri); auto result = FindStorage(uri);
if (!result.uri.empty()) if (!result.uri.empty())
@ -192,7 +192,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
Directory &directory = root.Make(uri); Directory &directory = root.Make(uri);
assert(!directory.storage); assert(!directory.storage);
@ -202,7 +202,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return root.Unmount(uri); return root.Unmount(uri);
} }
@ -231,7 +231,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
std::exception_ptr error; std::exception_ptr error;
@ -257,7 +257,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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);
@ -284,7 +284,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
@ -296,7 +296,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
@ -308,7 +308,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
if (root.storage != nullptr) { if (root.storage != nullptr) {
auto result = root.storage->MapToRelativeUTF8(uri); auto result = root.storage->MapToRelativeUTF8(uri);
@ -325,7 +325,7 @@ CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept
InputStreamPtr InputStreamPtr
CompositeStorage::OpenFile(std::string_view uri_utf8, Mutex &_mutex) CompositeStorage::OpenFile(std::string_view uri_utf8, Mutex &_mutex)
{ {
const std::lock_guard<Mutex> lock(mutex); const std::lock_guard lock{mutex};
auto f = FindStorage(uri_utf8); auto f = FindStorage(uri_utf8);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)

View File

@ -99,7 +99,7 @@ public:
*/ */
template<typename T> template<typename T>
void VisitMounts(T t) const { void VisitMounts(T t) const {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
std::string uri; std::string uri;
VisitMounts(uri, root, t); VisitMounts(uri, root, t);
} }
@ -109,7 +109,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
return IsMounted(root, storage_uri); return IsMounted(root, storage_uri);
} }

View File

@ -109,7 +109,7 @@ public:
} }
void Wait() { void Wait() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
cond.wait(lock, [this]{ return done; }); cond.wait(lock, [this]{ return done; });
if (postponed_error) if (postponed_error)
@ -130,7 +130,7 @@ protected:
} }
void LockSetDone() { void LockSetDone() {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
SetDone(); SetDone();
} }
@ -148,7 +148,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::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
postponed_error = std::move(e); postponed_error = std::move(e);
SetDone(); SetDone();
} }

View File

@ -140,7 +140,7 @@ private:
void SetState(State _state) noexcept { void SetState(State _state) noexcept {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
state = _state; state = _state;
cond.notify_all(); cond.notify_all();
} }
@ -148,7 +148,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::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
state = _state; state = _state;
last_exception = std::move(e); last_exception = std::move(e);
cond.notify_all(); cond.notify_all();
@ -172,7 +172,7 @@ private:
} }
void WaitConnected() { void WaitConnected() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
while (true) { while (true) {
switch (state) { switch (state) {

View File

@ -89,7 +89,7 @@ GetInfo(SmbclientContext &ctx, Mutex &mutex, const char *path)
struct stat st; struct stat st;
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock 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");
} }
@ -131,7 +131,7 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8)
SMBCFILE *handle; SMBCFILE *handle;
{ {
const std::scoped_lock<Mutex> protect(mutex); const std::scoped_lock protect{mutex};
handle = ctx.OpenDirectory(mapped.c_str()); handle = ctx.OpenDirectory(mapped.c_str());
} }
@ -152,14 +152,14 @@ SkipNameFS(PathTraitsFS::const_pointer name) noexcept
SmbclientDirectoryReader::~SmbclientDirectoryReader() SmbclientDirectoryReader::~SmbclientDirectoryReader()
{ {
const std::scoped_lock<Mutex> lock(storage.mutex); const std::scoped_lock lock{storage.mutex};
storage.ctx.CloseDirectory(handle); storage.ctx.CloseDirectory(handle);
} }
const char * const char *
SmbclientDirectoryReader::Read() noexcept SmbclientDirectoryReader::Read() noexcept
{ {
const std::scoped_lock<Mutex> protect(storage.mutex); const std::scoped_lock protect{storage.mutex};
while (auto e = storage.ctx.ReadDirectory(handle)) { while (auto e = storage.ctx.ReadDirectory(handle)) {
name = e->name; name = e->name;

View File

@ -151,7 +151,7 @@ UdisksStorage::SetMountPoint(Path mount_point)
void void
UdisksStorage::LockSetMountPoint(Path mount_point) UdisksStorage::LockSetMountPoint(Path mount_point)
{ {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
SetMountPoint(mount_point); SetMountPoint(mount_point);
} }
@ -183,7 +183,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
return; return;
} }
} catch (...) { } catch (...) {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
@ -196,7 +196,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
void void
UdisksStorage::MountWait() UdisksStorage::MountWait()
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (mounted_storage) if (mounted_storage)
/* already mounted */ /* already mounted */
@ -239,7 +239,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::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
@ -258,7 +258,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::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = std::current_exception(); mount_error = std::current_exception();
want_mount = false; want_mount = false;
cond.notify_all(); cond.notify_all();
@ -267,7 +267,7 @@ try {
void void
UdisksStorage::UnmountWait() UdisksStorage::UnmountWait()
{ {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
if (!mounted_storage) if (!mounted_storage)
/* not mounted */ /* not mounted */
@ -296,7 +296,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::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = std::current_exception(); mount_error = std::current_exception();
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();
@ -308,12 +308,12 @@ try {
using namespace ODBus; using namespace ODBus;
reply.CheckThrowError(); reply.CheckThrowError();
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = {}; mount_error = {};
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();
} catch (...) { } catch (...) {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
mount_error = std::current_exception(); mount_error = std::current_exception();
mounted_storage.reset(); mounted_storage.reset();
cond.notify_all(); cond.notify_all();

View File

@ -23,7 +23,7 @@ struct ApeFooter {
bool bool
tag_ape_scan(InputStream &is, const ApeTagCallback& callback) tag_ape_scan(InputStream &is, const ApeTagCallback& callback)
try { try {
std::unique_lock<Mutex> lock(is.mutex); std::unique_lock lock{is.mutex};
if (!is.KnownSize() || !is.CheapSeeking()) if (!is.KnownSize() || !is.CheapSeeking())
return false; return false;

View File

@ -20,7 +20,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) {
items.reserve(other.num_items); items.reserve(other.num_items);
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock 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]));
} }
@ -54,7 +54,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::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock protect{tag_pool_lock};
for (auto &i : items) for (auto &i : items)
i = tag_pool_dup_item(i); i = tag_pool_dup_item(i);
} }
@ -170,7 +170,7 @@ TagBuilder::Complement(const Tag &other) noexcept
items.reserve(items.size() + n); items.reserve(items.size() + n);
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock 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])
@ -185,7 +185,7 @@ TagBuilder::AddItemUnchecked(TagType type, std::string_view value) noexcept
TagItem *i; TagItem *i;
{ {
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock protect{tag_pool_lock};
i = tag_pool_get_item(type, value); i = tag_pool_get_item(type, value);
} }
@ -228,7 +228,7 @@ TagBuilder::RemoveAll() noexcept
return; return;
{ {
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock protect{tag_pool_lock};
for (auto i : items) for (auto i : items)
tag_pool_put_item(i); tag_pool_put_item(i);
} }
@ -246,7 +246,7 @@ TagBuilder::RemoveType(TagType type) noexcept
const auto begin = items.begin(), end = items.end(); const auto begin = items.begin(), end = items.end();
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock protect{tag_pool_lock};
items.erase(std::remove_if(begin, end, items.erase(std::remove_if(begin, end,
[type](TagItem *item) { [type](TagItem *item) {
if (item->type != type) if (item->type != type)

View File

@ -193,7 +193,7 @@ try {
UniqueId3Tag UniqueId3Tag
tag_id3_load(InputStream &is) tag_id3_load(InputStream &is)
try { try {
std::unique_lock<Mutex> lock(is.mutex); std::unique_lock lock{is.mutex};
auto tag = tag_id3_find_from_beginning(is, lock); auto tag = tag_id3_find_from_beginning(is, lock);
if (tag == nullptr && is.CheapSeeking()) { if (tag == nullptr && is.CheapSeeking()) {

View File

@ -15,7 +15,7 @@ Tag::Clear() noexcept
if (num_items > 0) { if (num_items > 0) {
assert(items != nullptr); assert(items != nullptr);
const std::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock 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]);
num_items = 0; num_items = 0;
@ -32,7 +32,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::scoped_lock<Mutex> protect(tag_pool_lock); const std::scoped_lock 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]);
} }

View File

@ -22,7 +22,7 @@ class SafeSingleton {
public: public:
template<typename... Args> template<typename... Args>
explicit SafeSingleton(Args&&... args) { explicit SafeSingleton(Args&&... args) {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
if (ref == 0) if (ref == 0)
instance = new T(std::forward<Args>(args)...); instance = new T(std::forward<Args>(args)...);
@ -34,7 +34,7 @@ public:
} }
~SafeSingleton() noexcept { ~SafeSingleton() noexcept {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
if (--ref > 0) if (--ref > 0)
return; return;

View File

@ -70,24 +70,24 @@ private:
public: public:
bool is_ready() const noexcept { bool is_ready() const noexcept {
std::unique_lock<CriticalSection> lock(mutex); const std::lock_guard lock{mutex};
return ready; return ready;
} }
bool already_retrieved() const noexcept { bool already_retrieved() const noexcept {
std::unique_lock<CriticalSection> lock(mutex); const std::lock_guard lock{mutex};
return retrieved; return retrieved;
} }
void wait() { void wait() {
std::unique_lock<CriticalSection> lock(mutex); std::unique_lock lock{mutex};
condition.wait(lock, [this]() { return ready; }); condition.wait(lock, [this]() { return ready; });
} }
template <class Rep, class Period> template <class Rep, class Period>
WinFutureStatus WinFutureStatus
wait_for(const std::chrono::duration<Rep, Period> &timeout_duration) const { wait_for(const std::chrono::duration<Rep, Period> &timeout_duration) const {
std::unique_lock<CriticalSection> lock(mutex); std::unique_lock lock{mutex};
// deferred function not support yet // deferred function not support yet
if (condition.wait_for(lock, timeout_duration, if (condition.wait_for(lock, timeout_duration,
[this]() { return ready; })) { [this]() { return ready; })) {
@ -97,7 +97,7 @@ public:
} }
virtual T &get_value() { virtual T &get_value() {
std::unique_lock<CriticalSection> lock(mutex); std::unique_lock lock{mutex};
if (retrieved) { if (retrieved) {
throw WinFutureError(WinFutureErrc::future_already_retrieved); throw WinFutureError(WinFutureErrc::future_already_retrieved);
} }
@ -113,7 +113,7 @@ public:
} }
void set_value(const T &value) { void set_value(const T &value) {
std::unique_lock<CriticalSection> lock(mutex); const std::lock_guard lock{mutex};
if (!std::holds_alternative<std::monostate>(result)) { if (!std::holds_alternative<std::monostate>(result)) {
throw WinFutureError(WinFutureErrc::promise_already_satisfied); throw WinFutureError(WinFutureErrc::promise_already_satisfied);
} }
@ -123,7 +123,7 @@ public:
} }
void set_value(T &&value) { void set_value(T &&value) {
std::unique_lock<CriticalSection> lock(mutex); const std::lock_guard lock{mutex};
if (!std::holds_alternative<std::monostate>(result)) { if (!std::holds_alternative<std::monostate>(result)) {
throw WinFutureError(WinFutureErrc::promise_already_satisfied); throw WinFutureError(WinFutureErrc::promise_already_satisfied);
} }
@ -133,7 +133,7 @@ public:
} }
void set_exception(std::exception_ptr eptr) { void set_exception(std::exception_ptr eptr) {
std::unique_lock<CriticalSection> lock(mutex); const std::lock_guard lock{mutex};
if (!std::holds_alternative<std::monostate>(result)) { if (!std::holds_alternative<std::monostate>(result)) {
throw WinFutureError(WinFutureErrc::promise_already_satisfied); throw WinFutureError(WinFutureErrc::promise_already_satisfied);
} }

View File

@ -52,7 +52,7 @@ TEST(RewindInputStream, Basic)
EXPECT_TRUE(ris.get() != sis); EXPECT_TRUE(ris.get() != sis);
EXPECT_TRUE(ris != nullptr); EXPECT_TRUE(ris != nullptr);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
ris->Update(); ris->Update();
EXPECT_TRUE(ris->IsReady()); EXPECT_TRUE(ris->IsReady());

View File

@ -54,7 +54,7 @@ dump_input_stream(InputStreamPtr &&is)
dump_text_file(tis); dump_text_file(tis);
} }
const std::scoped_lock<Mutex> protect(is->mutex); const std::scoped_lock protect{is->mutex};
is->Check(); is->Check();
return 0; return 0;

View File

@ -149,7 +149,7 @@ dump_input_stream(InputStream &is, FileDescriptor out,
{ {
out.SetBinaryMode(); out.SetBinaryMode();
std::unique_lock<Mutex> lock(is.mutex); std::unique_lock lock{is.mutex};
if (seek > 0) if (seek > 0)
is.Seek(lock, seek); is.Seek(lock, seek);
@ -195,7 +195,7 @@ class DumpRemoteTagHandler final : public RemoteTagHandler {
public: public:
Tag Wait() { Tag Wait() {
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
cond.wait(lock, [this]{ return done; }); cond.wait(lock, [this]{ return done; });
if (error) if (error)
@ -206,14 +206,14 @@ public:
/* virtual methods from RemoteTagHandler */ /* virtual methods from RemoteTagHandler */
void OnRemoteTag(Tag &&_tag) noexcept override { void OnRemoteTag(Tag &&_tag) noexcept override {
const std::scoped_lock<Mutex> lock(mutex); const std::scoped_lock 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::scoped_lock<Mutex> lock(mutex); const std::scoped_lock lock{mutex};
error = std::move(e); error = std::move(e);
done = true; done = true;
cond.notify_all(); cond.notify_all();

View File

@ -253,7 +253,7 @@ Cat(Storage &storage, const char *path)
auto is = storage.OpenFile(path, mutex); auto is = storage.OpenFile(path, mutex);
assert(is); assert(is);
std::unique_lock<Mutex> lock(mutex); std::unique_lock lock{mutex};
WaitReady(*is, lock); WaitReady(*is, lock);
Cat(*is, lock, FileDescriptor{STDOUT_FILENO}); Cat(*is, lock, FileDescriptor{STDOUT_FILENO});