Skip to content

Commit

Permalink
*: use std::scoped_lock with implicit template parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed May 23, 2024
1 parent 4fc3230 commit 381215f
Show file tree
Hide file tree
Showing 68 changed files with 253 additions and 253 deletions.
4 changes: 2 additions & 2 deletions src/MusicBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks)
MusicChunkPtr
MusicBuffer::Allocate() noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return {buffer.Allocate(), MusicChunkDeleter(*this)};
}

Expand All @@ -30,7 +30,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept
chunk->next.reset();
chunk->other.reset();

const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};

assert(!chunk->other || !chunk->other->other);

Expand Down
2 changes: 1 addition & 1 deletion src/MusicBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public:
#endif

bool IsFull() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return buffer.IsFull();
}

Expand Down
6 changes: 3 additions & 3 deletions src/MusicPipe.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
bool
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())
if (i == chunk)
Expand All @@ -25,7 +25,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept
MusicChunkPtr
MusicPipe::Shift() noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};

auto chunk = std::move(head);
if (chunk != nullptr) {
Expand Down Expand Up @@ -65,7 +65,7 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept
assert(!chunk->IsEmpty());
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(!audio_format.IsDefined() ||
Expand Down
4 changes: 2 additions & 2 deletions src/MusicPipe.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public:
*/
[[gnu::pure]]
const MusicChunk *Peek() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return head.get();
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/RemoteTagCache.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RemoteTagCache::~RemoteTagCache() noexcept
void
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);
if (value) {
Expand Down Expand Up @@ -80,7 +80,7 @@ RemoteTagCache::ItemResolved(Item &item) noexcept
void
RemoteTagCache::InvokeHandlers() noexcept
{
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};

while (!invoke_list.empty()) {
auto &item = invoke_list.pop_front();
Expand All @@ -105,7 +105,7 @@ RemoteTagCache::Item::OnRemoteTag(Tag &&_tag) noexcept

scanner.reset();

const std::scoped_lock<Mutex> lock(parent.mutex);
const std::scoped_lock lock{parent.mutex};
parent.ItemResolved(*this);
}

Expand All @@ -117,6 +117,6 @@ RemoteTagCache::Item::OnRemoteTagError(std::exception_ptr e) noexcept

scanner.reset();

const std::scoped_lock<Mutex> lock(parent.mutex);
const std::scoped_lock lock{parent.mutex};
parent.ItemResolved(*this);
}
2 changes: 1 addition & 1 deletion src/command/FileCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ read_stream_art(Response &r, const std::string_view art_directory,

std::size_t read_size = 0;
if (buffer_size > 0) {
std::unique_lock<Mutex> lock(is->mutex);
std::unique_lock lock{is->mutex};
is->Seek(lock, offset);
read_size = is->Read(lock, {buffer.get(), buffer_size});
}
Expand Down
8 changes: 4 additions & 4 deletions src/command/FingerprintCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GetChromaprintCommand final
}

void CancelThread() noexcept override {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
cancel = true;
cond.notify_one();
}
Expand Down Expand Up @@ -188,7 +188,7 @@ GetChromaprintCommand::DecodeFile(std::string_view suffix, InputStream &is,
return false;

{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
if (cancel)
throw StopDecoder();
}
Expand Down Expand Up @@ -257,7 +257,7 @@ GetChromaprintCommand::OpenUri(const char *uri2)
auto is = InputStream::Open(uri2, mutex);
is->SetHandler(this);

std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
while (true) {
if (cancel)
throw StopDecoder();
Expand All @@ -282,7 +282,7 @@ GetChromaprintCommand::Read(InputStream &is,
if (dest.empty())
return 0;

std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};

while (true) {
if (cancel)
Expand Down
4 changes: 2 additions & 2 deletions src/db/update/Remove.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ UpdateRemoveService::RunDeferred() noexcept
std::forward_list<std::string> copy;

{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
std::swap(uris, copy);
}

Expand All @@ -39,7 +39,7 @@ UpdateRemoveService::Remove(std::string &&uri)
bool was_empty;

{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
was_empty = uris.empty();
uris.emplace_front(std::move(uri));
}
Expand Down
14 changes: 7 additions & 7 deletions src/decoder/Bridge.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ NeedChunks(DecoderControl &dc, std::unique_lock<Mutex> &lock) noexcept
static DecoderCommand
LockNeedChunks(DecoderControl &dc) noexcept
{
std::unique_lock<Mutex> lock(dc.mutex);
std::unique_lock lock{dc.mutex};
return NeedChunks(dc, lock);
}

Expand Down Expand Up @@ -135,7 +135,7 @@ DecoderBridge::FlushChunk() noexcept
if (!chunk->IsEmpty())
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();
}

Expand Down Expand Up @@ -197,7 +197,7 @@ DecoderBridge::GetVirtualCommand() noexcept
DecoderCommand
DecoderBridge::LockGetVirtualCommand() noexcept
{
const std::scoped_lock<Mutex> protect(dc.mutex);
const std::scoped_lock protect{dc.mutex};
return GetVirtualCommand();
}

Expand Down Expand Up @@ -257,7 +257,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
seekable);

{
const std::scoped_lock<Mutex> protect(dc.mutex);
const std::scoped_lock protect{dc.mutex};
dc.SetReady(audio_format, seekable, duration);
}

Expand All @@ -283,7 +283,7 @@ DecoderBridge::GetCommand() noexcept
void
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::SEEK ||
Expand Down Expand Up @@ -379,7 +379,7 @@ DecoderBridge::OpenUri(const char *uri)
auto is = InputStream::Open(uri, mutex);
is->SetHandler(&dc);

std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
while (true) {
if (dc.command == DecoderCommand::STOP)
throw StopDecoder();
Expand All @@ -403,7 +403,7 @@ try {
if (dest.empty())
return 0;

std::unique_lock<Mutex> lock(is.mutex);
std::unique_lock lock{is.mutex};

while (true) {
if (CheckCancelRead())
Expand Down
14 changes: 7 additions & 7 deletions src/decoder/Control.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public:

[[gnu::pure]]
bool LockIsIdle() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return IsIdle();
}

Expand All @@ -225,7 +225,7 @@ public:

[[gnu::pure]]
bool LockIsStarting() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return IsStarting();
}

Expand All @@ -237,13 +237,13 @@ public:

[[gnu::pure]]
bool LockHasFailed() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return HasFailed();
}

[[gnu::pure]]
bool LockIsReplayGainEnabled() const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return replay_gain_mode != ReplayGainMode::OFF;
}

Expand Down Expand Up @@ -274,7 +274,7 @@ public:
* Like CheckRethrowError(), but locks and unlocks the object.
*/
void LockCheckRethrowError() const {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
CheckRethrowError();
}

Expand Down Expand Up @@ -344,13 +344,13 @@ private:
* object.
*/
void LockSynchronousCommand(DecoderCommand cmd) noexcept {
std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
ClearError();
SynchronousCommandLocked(lock, cmd);
}

void LockAsynchronousCommand(DecoderCommand cmd) noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
command = cmd;
Signal();
}
Expand Down
12 changes: 6 additions & 6 deletions src/decoder/Thread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ TryUriDecode(DecoderBridge &bridge, const char *uri)
if (!plugin.SupportsUri(uri))
return false;

std::unique_lock<Mutex> lock(bridge.dc.mutex);
std::unique_lock lock{bridge.dc.mutex};
bridge.Reset();
return DecoderUriDecode(plugin, bridge, uri);
});
Expand All @@ -296,7 +296,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri)

MaybeLoadReplayGain(bridge, *input_stream);

std::unique_lock<Mutex> lock(dc.mutex);
std::unique_lock lock{dc.mutex};

bool tried = false;
return dc.command == DecoderCommand::STOP ||
Expand Down Expand Up @@ -326,10 +326,10 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, std::string_view suffix,
DecoderControl &dc = bridge.dc;

if (plugin.file_decode != nullptr) {
const std::scoped_lock<Mutex> protect(dc.mutex);
const std::scoped_lock protect{dc.mutex};
return decoder_file_decode(plugin, bridge, path_fs);
} else if (plugin.stream_decode != nullptr) {
std::unique_lock<Mutex> lock(dc.mutex);
std::unique_lock lock{dc.mutex};
return decoder_stream_decode(plugin, bridge, input_stream,
lock);
} else
Expand All @@ -354,7 +354,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs,
bridge.Reset();

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);
}

Expand Down Expand Up @@ -545,7 +545,7 @@ DecoderControl::RunThread() noexcept
{
SetThreadName("decoder");

std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};

do {
assert(state == DecoderState::STOP ||
Expand Down
4 changes: 2 additions & 2 deletions src/input/AsyncInputStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ AsyncInputStream::AppendToBuffer(std::span<const std::byte> src) noexcept
void
AsyncInputStream::DeferredResume() noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};

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

Expand Down
4 changes: 2 additions & 2 deletions src/input/BufferingInputStream.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ BufferingInputStream::BufferingInputStream(InputStreamPtr _input)
BufferingInputStream::~BufferingInputStream() noexcept
{
{
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
stop = true;
wake_cond.notify_one();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ BufferingInputStream::RunThread() noexcept
{
SetThreadName("buffering");

std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};

try {
RunThreadLocked(lock);
Expand Down

0 comments on commit 381215f

Please sign in to comment.