thread/Mutex: remove ScopeLock, use std::lock_guard directly

This commit is contained in:
Max Kellermann 2017-01-03 07:11:57 +01:00
parent a42021655c
commit 2e182e84c3
51 changed files with 158 additions and 160 deletions

View File

@ -72,7 +72,7 @@ io_thread_start()
assert(io.loop != nullptr); assert(io.loop != nullptr);
assert(!io.thread.IsDefined()); assert(!io.thread.IsDefined());
const ScopeLock protect(io.mutex); const std::lock_guard<Mutex> protect(io.mutex);
io.thread.Start(io_thread_func, nullptr); io.thread.Start(io_thread_func, nullptr);
} }

View File

@ -30,7 +30,7 @@ MusicBuffer::MusicBuffer(unsigned num_chunks)
MusicChunk * MusicChunk *
MusicBuffer::Allocate() MusicBuffer::Allocate()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return buffer.Allocate(); return buffer.Allocate();
} }
@ -39,7 +39,7 @@ MusicBuffer::Return(MusicChunk *chunk)
{ {
assert(chunk != nullptr); assert(chunk != nullptr);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (chunk->other != nullptr) { if (chunk->other != nullptr) {
assert(chunk->other->other == nullptr); assert(chunk->other->other == nullptr);

View File

@ -27,7 +27,7 @@
bool bool
MusicPipe::Contains(const MusicChunk *chunk) const MusicPipe::Contains(const MusicChunk *chunk) const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
for (const MusicChunk *i = head; i != nullptr; i = i->next) for (const MusicChunk *i = head; i != nullptr; i = i->next)
if (i == chunk) if (i == chunk)
@ -41,7 +41,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const
MusicChunk * MusicChunk *
MusicPipe::Shift() MusicPipe::Shift()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
MusicChunk *chunk = head; MusicChunk *chunk = head;
if (chunk != nullptr) { if (chunk != nullptr) {
@ -87,7 +87,7 @@ MusicPipe::Push(MusicChunk *chunk)
assert(!chunk->IsEmpty()); assert(!chunk->IsEmpty());
assert(chunk->length == 0 || chunk->audio_format.IsValid()); assert(chunk->length == 0 || chunk->audio_format.IsValid());
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(size > 0 || !audio_format.IsDefined()); assert(size > 0 || !audio_format.IsDefined());
assert(!audio_format.IsDefined() || assert(!audio_format.IsDefined() ||

View File

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

View File

@ -88,7 +88,7 @@ need_chunks(DecoderControl &dc)
static DecoderCommand static DecoderCommand
LockNeedChunks(DecoderControl &dc) LockNeedChunks(DecoderControl &dc)
{ {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
return need_chunks(dc); return need_chunks(dc);
} }
@ -130,7 +130,7 @@ DecoderBridge::FlushChunk()
else else
dc.pipe->Push(chunk); dc.pipe->Push(chunk);
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
if (dc.client_is_waiting) if (dc.client_is_waiting)
dc.client_cond.signal(); dc.client_cond.signal();
} }
@ -193,7 +193,7 @@ DecoderBridge::GetVirtualCommand()
DecoderCommand DecoderCommand
DecoderBridge::LockGetVirtualCommand() DecoderBridge::LockGetVirtualCommand()
{ {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
return GetVirtualCommand(); return GetVirtualCommand();
} }
@ -258,7 +258,7 @@ DecoderBridge::Ready(const AudioFormat audio_format,
seekable ? "true" : "false"); seekable ? "true" : "false");
{ {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
dc.SetReady(audio_format, seekable, duration); dc.SetReady(audio_format, seekable, duration);
} }
@ -287,7 +287,7 @@ DecoderBridge::GetCommand()
void void
DecoderBridge::CommandFinished() DecoderBridge::CommandFinished()
{ {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
assert(dc.command != DecoderCommand::NONE || initial_seek_running); assert(dc.command != DecoderCommand::NONE || initial_seek_running);
assert(dc.command != DecoderCommand::SEEK || assert(dc.command != DecoderCommand::SEEK ||
@ -376,7 +376,7 @@ DecoderBridge::OpenUri(const char *uri)
auto is = InputStream::Open(uri, mutex, cond); auto is = InputStream::Open(uri, mutex, cond);
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
while (true) { while (true) {
is->Update(); is->Update();
if (is->IsReady()) if (is->IsReady())
@ -399,7 +399,7 @@ try {
if (length == 0) if (length == 0)
return 0; return 0;
ScopeLock lock(is.mutex); std::lock_guard<Mutex> lock(is.mutex);
while (true) { while (true) {
if (CheckCancelRead()) if (CheckCancelRead())

View File

@ -111,7 +111,7 @@ DecoderControl::Start(DetachedSong *_song,
void void
DecoderControl::Stop() DecoderControl::Stop()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (command != DecoderCommand::NONE) if (command != DecoderCommand::NONE)
/* Attempt to cancel the current command. If it's too /* Attempt to cancel the current command. If it's too

View File

@ -228,7 +228,7 @@ struct DecoderControl {
gcc_pure gcc_pure
bool LockIsIdle() const { bool LockIsIdle() const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return IsIdle(); return IsIdle();
} }
@ -238,7 +238,7 @@ struct DecoderControl {
gcc_pure gcc_pure
bool LockIsStarting() const { bool LockIsStarting() const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return IsStarting(); return IsStarting();
} }
@ -250,7 +250,7 @@ struct DecoderControl {
gcc_pure gcc_pure
bool LockHasFailed() const { bool LockHasFailed() const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return HasFailed(); return HasFailed();
} }
@ -281,7 +281,7 @@ struct DecoderControl {
* Like CheckRethrowError(), but locks and unlocks the object. * Like CheckRethrowError(), but locks and unlocks the object.
*/ */
void LockCheckRethrowError() const { void LockCheckRethrowError() const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CheckRethrowError(); CheckRethrowError();
} }
@ -309,7 +309,7 @@ struct DecoderControl {
gcc_pure gcc_pure
bool LockIsCurrentSong(const DetachedSong &_song) const { bool LockIsCurrentSong(const DetachedSong &_song) const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return IsCurrentSong(_song); return IsCurrentSong(_song);
} }
@ -346,13 +346,13 @@ private:
* object. * object.
*/ */
void LockSynchronousCommand(DecoderCommand cmd) { void LockSynchronousCommand(DecoderCommand cmd) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ClearError(); ClearError();
SynchronousCommandLocked(cmd); SynchronousCommandLocked(cmd);
} }
void LockAsynchronousCommand(DecoderCommand cmd) { void LockAsynchronousCommand(DecoderCommand cmd) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
command = cmd; command = cmd;
Signal(); Signal();
} }

View File

@ -61,7 +61,7 @@ decoder_input_stream_open(DecoderControl &dc, const char *uri)
/* wait for the input stream to become ready; its metadata /* wait for the input stream to become ready; its metadata
will be available then */ will be available then */
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
is->Update(); is->Update();
while (!is->IsReady()) { while (!is->IsReady()) {
@ -264,7 +264,7 @@ static void
MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is) MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is)
{ {
{ {
const ScopeLock protect(bridge.dc.mutex); const std::lock_guard<Mutex> protect(bridge.dc.mutex);
if (bridge.dc.replay_gain_mode == ReplayGainMode::OFF) if (bridge.dc.replay_gain_mode == ReplayGainMode::OFF)
/* ReplayGain is disabled */ /* ReplayGain is disabled */
return; return;
@ -288,7 +288,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri)
MaybeLoadReplayGain(bridge, *input_stream); MaybeLoadReplayGain(bridge, *input_stream);
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
bool tried = false; bool tried = false;
return dc.command == DecoderCommand::STOP || return dc.command == DecoderCommand::STOP ||
@ -318,10 +318,10 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, const char *suffix,
DecoderControl &dc = bridge.dc; DecoderControl &dc = bridge.dc;
if (plugin.file_decode != nullptr) { if (plugin.file_decode != nullptr) {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
return decoder_file_decode(plugin, bridge, path_fs); return decoder_file_decode(plugin, bridge, path_fs);
} else if (plugin.stream_decode != nullptr) { } else if (plugin.stream_decode != nullptr) {
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
return decoder_stream_decode(plugin, bridge, input_stream); return decoder_stream_decode(plugin, bridge, input_stream);
} else } else
return false; return false;
@ -344,7 +344,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix,
bridge.error = nullptr; bridge.error = nullptr;
DecoderControl &dc = bridge.dc; DecoderControl &dc = bridge.dc;
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
return decoder_file_decode(plugin, bridge, path_fs); return decoder_file_decode(plugin, bridge, path_fs);
} }
@ -517,7 +517,7 @@ decoder_task(void *arg)
SetThreadName("decoder"); SetThreadName("decoder");
const ScopeLock protect(dc.mutex); const std::lock_guard<Mutex> protect(dc.mutex);
do { do {
assert(dc.state == DecoderState::STOP || assert(dc.state == DecoderState::STOP ||

View File

@ -254,7 +254,7 @@ EventLoop::AddDeferred(DeferredMonitor &d)
void void
EventLoop::RemoveDeferred(DeferredMonitor &d) EventLoop::RemoveDeferred(DeferredMonitor &d)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (!d.pending) { if (!d.pending) {
assert(std::find(deferred.begin(), assert(std::find(deferred.begin(),

View File

@ -240,7 +240,7 @@ AsyncInputStream::AppendToBuffer(const void *data, size_t append_size)
void void
AsyncInputStream::DeferredResume() AsyncInputStream::DeferredResume()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
try { try {
Resume(); Resume();
@ -253,7 +253,7 @@ AsyncInputStream::DeferredResume()
void void
AsyncInputStream::DeferredSeek() AsyncInputStream::DeferredSeek()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (seek_state != SeekState::SCHEDULED) if (seek_state != SeekState::SCHEDULED)
return; return;

View File

@ -64,7 +64,7 @@ InputStream::WaitReady()
void void
InputStream::LockWaitReady() InputStream::LockWaitReady()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
WaitReady(); WaitReady();
} }
@ -96,14 +96,14 @@ InputStream::Seek(gcc_unused offset_type new_offset)
void void
InputStream::LockSeek(offset_type _offset) InputStream::LockSeek(offset_type _offset)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
Seek(_offset); Seek(_offset);
} }
void void
InputStream::LockSkip(offset_type _offset) InputStream::LockSkip(offset_type _offset)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
Skip(_offset); Skip(_offset);
} }
@ -116,7 +116,7 @@ InputStream::ReadTag()
Tag * Tag *
InputStream::LockReadTag() InputStream::LockReadTag()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return ReadTag(); return ReadTag();
} }
@ -135,7 +135,7 @@ InputStream::LockRead(void *ptr, size_t _size)
#endif #endif
assert(_size > 0); assert(_size > 0);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return Read(ptr, _size); return Read(ptr, _size);
} }
@ -164,13 +164,13 @@ InputStream::LockReadFull(void *ptr, size_t _size)
#endif #endif
assert(_size > 0); assert(_size > 0);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ReadFull(ptr, _size); ReadFull(ptr, _size);
} }
bool bool
InputStream::LockIsEOF() InputStream::LockIsEOF()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return IsEOF(); return IsEOF();
} }

View File

@ -59,7 +59,7 @@ InputStream::OpenReady(const char *uri,
auto is = Open(uri, mutex, cond); auto is = Open(uri, mutex, cond);
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
is->WaitReady(); is->WaitReady();
is->Check(); is->Check();
} }

View File

@ -29,7 +29,7 @@
ThreadInputStream::~ThreadInputStream() ThreadInputStream::~ThreadInputStream()
{ {
{ {
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
close = true; close = true;
wake_cond.signal(); wake_cond.signal();
} }
@ -62,7 +62,7 @@ ThreadInputStream::ThreadFunc()
{ {
FormatThreadName("input:%s", plugin); FormatThreadName("input:%s", plugin);
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
try { try {
Open(); Open();

View File

@ -192,7 +192,7 @@ AlsaInputStream::PrepareSockets()
void void
AlsaInputStream::DispatchSockets() AlsaInputStream::DispatchSockets()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto w = PrepareWriteBuffer(); auto w = PrepareWriteBuffer();
const snd_pcm_uframes_t w_frames = w.size / frame_size; const snd_pcm_uframes_t w_frames = w.size / frame_size;

View File

@ -429,7 +429,7 @@ CurlInputStream::RequestDone(CURLcode result, long status)
FreeEasy(); FreeEasy();
AsyncInputStream::SetClosed(); AsyncInputStream::SetClosed();
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (result != CURLE_OK) { if (result != CURLE_OK) {
postponed_exception = std::make_exception_ptr(FormatRuntimeError("curl failed: %s", postponed_exception = std::make_exception_ptr(FormatRuntimeError("curl failed: %s",
@ -693,7 +693,7 @@ CurlInputStream::DataReceived(const void *ptr, size_t received_size)
{ {
assert(received_size > 0); assert(received_size > 0);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (IsSeekPending()) if (IsSeekPending())
SeekDone(); SeekDone();

View File

@ -142,7 +142,7 @@ NfsInputStream::DoSeek(offset_type new_offset)
void void
NfsInputStream::OnNfsFileOpen(uint64_t _size) NfsInputStream::OnNfsFileOpen(uint64_t _size)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (reconnecting) { if (reconnecting) {
/* reconnect has succeeded */ /* reconnect has succeeded */
@ -162,7 +162,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size)
void void
NfsInputStream::OnNfsFileRead(const void *data, size_t data_size) NfsInputStream::OnNfsFileRead(const void *data, size_t data_size)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(!IsBufferFull()); assert(!IsBufferFull());
assert(IsBufferFull() == (GetBufferSpace() == 0)); assert(IsBufferFull() == (GetBufferSpace() == 0));
AppendToBuffer(data, data_size); AppendToBuffer(data, data_size);
@ -175,7 +175,7 @@ NfsInputStream::OnNfsFileRead(const void *data, size_t data_size)
void void
NfsInputStream::OnNfsFileError(std::exception_ptr &&e) NfsInputStream::OnNfsFileError(std::exception_ptr &&e)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (IsPaused()) { if (IsPaused()) {
/* while we're paused, don't report this error to the /* while we're paused, don't report this error to the

View File

@ -90,7 +90,7 @@ input_smbclient_open(const char *uri,
if (!StringStartsWith(uri, "smb://")) if (!StringStartsWith(uri, "smb://"))
return nullptr; return nullptr;
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
SMBCCTX *ctx = smbc_new_context(); SMBCCTX *ctx = smbc_new_context();
if (ctx == nullptr) if (ctx == nullptr)

View File

@ -105,7 +105,7 @@ AllocatedString<char>
IcuConverter::ToUTF8(const char *s) const IcuConverter::ToUTF8(const char *s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ucnv_resetToUnicode(converter); ucnv_resetToUnicode(converter);
@ -133,7 +133,7 @@ AllocatedString<char>
IcuConverter::FromUTF8(const char *s) const IcuConverter::FromUTF8(const char *s) const
{ {
#ifdef HAVE_ICU #ifdef HAVE_ICU
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
const auto u = UCharFromUTF8(s); const auto u = UCharFromUTF8(s);

View File

@ -60,7 +60,7 @@ public:
private: private:
bool LockWaitFinished() { bool LockWaitFinished() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
while (!finished) while (!finished)
if (!cond.timed_wait(mutex, timeout)) if (!cond.timed_wait(mutex, timeout))
return false; return false;
@ -73,7 +73,7 @@ private:
* thread. * thread.
*/ */
void LockSetFinished() { void LockSetFinished() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
finished = true; finished = true;
cond.signal(); cond.signal();
} }

View File

@ -43,7 +43,7 @@ mpd_smbc_get_auth_data(gcc_unused const char *srv,
void void
SmbclientInit() SmbclientInit()
{ {
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
constexpr int debug = 0; constexpr int debug = 0;
if (smbc_init(mpd_smbc_get_auth_data, debug) < 0) if (smbc_init(mpd_smbc_get_auth_data, debug) < 0)

View File

@ -61,7 +61,7 @@ UpnpClientGlobalInit(UpnpClient_Handle &handle)
UpnpGlobalInit(); UpnpGlobalInit();
try { try {
const ScopeLock protect(upnp_client_init_mutex); const std::lock_guard<Mutex> protect(upnp_client_init_mutex);
if (upnp_client_ref == 0) if (upnp_client_ref == 0)
DoInit(); DoInit();
} catch (...) { } catch (...) {
@ -77,7 +77,7 @@ void
UpnpClientGlobalFinish() UpnpClientGlobalFinish()
{ {
{ {
const ScopeLock protect(upnp_client_init_mutex); const std::lock_guard<Mutex> protect(upnp_client_init_mutex);
assert(upnp_client_ref > 0); assert(upnp_client_ref > 0);
if (--upnp_client_ref == 0) if (--upnp_client_ref == 0)

View File

@ -74,7 +74,7 @@ AnnounceLostUPnP(UPnPDiscoveryListener &listener, const UPnPDevice &device)
inline void inline void
UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d) UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
for (auto &i : directories) { for (auto &i : directories) {
if (i.id == d.id) { if (i.id == d.id) {
@ -92,7 +92,7 @@ UPnPDeviceDirectory::LockAdd(ContentDirectoryDescriptor &&d)
inline void inline void
UPnPDeviceDirectory::LockRemove(const std::string &id) UPnPDeviceDirectory::LockRemove(const std::string &id)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
for (auto i = directories.begin(), end = directories.end(); for (auto i = directories.begin(), end = directories.end();
i != end; ++i) { i != end; ++i) {
@ -273,7 +273,7 @@ UPnPDeviceDirectory::Search()
std::vector<ContentDirectoryService> std::vector<ContentDirectoryService>
UPnPDeviceDirectory::GetDirectories() UPnPDeviceDirectory::GetDirectories()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ExpireDevices(); ExpireDevices();
@ -293,7 +293,7 @@ UPnPDeviceDirectory::GetDirectories()
ContentDirectoryService ContentDirectoryService
UPnPDeviceDirectory::GetServer(const char *friendly_name) UPnPDeviceDirectory::GetServer(const char *friendly_name)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ExpireDevices(); ExpireDevices();

View File

@ -48,7 +48,7 @@ DoInit()
void void
UpnpGlobalInit() UpnpGlobalInit()
{ {
const ScopeLock protect(upnp_init_mutex); const std::lock_guard<Mutex> protect(upnp_init_mutex);
if (upnp_ref == 0) if (upnp_ref == 0)
DoInit(); DoInit();
@ -59,7 +59,7 @@ UpnpGlobalInit()
void void
UpnpGlobalFinish() UpnpGlobalFinish()
{ {
const ScopeLock protect(upnp_init_mutex); const std::lock_guard<Mutex> protect(upnp_init_mutex);
assert(upnp_ref > 0); assert(upnp_ref > 0);

View File

@ -90,7 +90,7 @@ public:
*/ */
bool start(unsigned nworkers, void *(*workproc)(void *), void *arg) bool start(unsigned nworkers, void *(*workproc)(void *), void *arg)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(nworkers > 0); assert(nworkers > 0);
assert(!ok); assert(!ok);
@ -120,7 +120,7 @@ public:
template<typename U> template<typename U>
bool put(U &&u) bool put(U &&u)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
queue.emplace(std::forward<U>(u)); queue.emplace(std::forward<U>(u));
@ -135,7 +135,7 @@ public:
*/ */
void setTerminateAndWait() void setTerminateAndWait()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
// Wait for all worker threads to have called workerExit() // Wait for all worker threads to have called workerExit()
ok = false; ok = false;
@ -166,7 +166,7 @@ public:
*/ */
bool take(T &tp) bool take(T &tp)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (!ok) if (!ok)
return false; return false;
@ -192,7 +192,7 @@ public:
*/ */
void workerExit() void workerExit()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
n_workers_exited++; n_workers_exited++;
ok = false; ok = false;

View File

@ -53,7 +53,7 @@ mixer_open(Mixer *mixer)
{ {
assert(mixer != nullptr); assert(mixer != nullptr);
const ScopeLock protect(mixer->mutex); const std::lock_guard<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
return; return;
@ -83,7 +83,7 @@ mixer_close(Mixer *mixer)
{ {
assert(mixer != nullptr); assert(mixer != nullptr);
const ScopeLock protect(mixer->mutex); const std::lock_guard<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
mixer_close_internal(mixer); mixer_close_internal(mixer);
@ -120,7 +120,7 @@ mixer_get_volume(Mixer *mixer)
if (mixer->plugin.global && !mixer->failed) if (mixer->plugin.global && !mixer->failed)
mixer_open(mixer); mixer_open(mixer);
const ScopeLock protect(mixer->mutex); const std::lock_guard<Mutex> protect(mixer->mutex);
if (mixer->open) { if (mixer->open) {
try { try {
@ -144,7 +144,7 @@ mixer_set_volume(Mixer *mixer, unsigned volume)
if (mixer->plugin.global && !mixer->failed) if (mixer->plugin.global && !mixer->failed)
mixer_open(mixer); mixer_open(mixer);
const ScopeLock protect(mixer->mutex); const std::lock_guard<Mutex> protect(mixer->mutex);
if (mixer->open) if (mixer->open)
mixer->SetVolume(volume); mixer->SetVolume(volume);

View File

@ -103,7 +103,7 @@ SmbclientNeighborExplorer::Close()
NeighborExplorer::List NeighborExplorer::List
SmbclientNeighborExplorer::GetList() const SmbclientNeighborExplorer::GetList() const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
/* /*
List list; List list;
for (const auto &i : servers) for (const auto &i : servers)
@ -172,7 +172,7 @@ static NeighborExplorer::List
DetectServers() DetectServers()
{ {
NeighborExplorer::List list; NeighborExplorer::List list;
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
ReadServers(list, "smb://"); ReadServers(list, "smb://");
return list; return list;
} }

View File

@ -23,7 +23,7 @@
void void
notify::Wait() notify::Wait()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
while (!pending) while (!pending)
cond.wait(mutex); cond.wait(mutex);
pending = false; pending = false;
@ -32,7 +32,7 @@ notify::Wait()
void void
notify::Signal() notify::Signal()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
pending = true; pending = true;
cond.signal(); cond.signal();
} }
@ -40,6 +40,6 @@ notify::Signal()
void void
notify::Clear() notify::Clear()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
pending = false; pending = false;
} }

View File

@ -440,7 +440,7 @@ public:
gcc_pure gcc_pure
bool LockIsChunkConsumed(const MusicChunk &chunk) { bool LockIsChunkConsumed(const MusicChunk &chunk) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return IsChunkConsumed(chunk); return IsChunkConsumed(chunk);
} }

View File

@ -109,12 +109,12 @@ MultipleOutputs::EnableDisable()
/* parallel execution */ /* parallel execution */
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock lock(ao->mutex); const std::lock_guard<Mutex> lock(ao->mutex);
ao->EnableDisableAsync(); ao->EnableDisableAsync();
} }
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock lock(ao->mutex); const std::lock_guard<Mutex> lock(ao->mutex);
ao->WaitForCommand(); ao->WaitForCommand();
} }
} }
@ -123,7 +123,7 @@ bool
MultipleOutputs::AllFinished() const MultipleOutputs::AllFinished() const
{ {
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock protect(ao->mutex); const std::lock_guard<Mutex> protect(ao->mutex);
if (ao->IsOpen() && !ao->IsCommandFinished()) if (ao->IsOpen() && !ao->IsCommandFinished())
return false; return false;
} }
@ -215,7 +215,7 @@ MultipleOutputs::Open(const AudioFormat audio_format,
std::exception_ptr first_error; std::exception_ptr first_error;
for (auto ao : outputs) { for (auto ao : outputs) {
const ScopeLock lock(ao->mutex); const std::lock_guard<Mutex> lock(ao->mutex);
if (ao->IsEnabled()) if (ao->IsEnabled())
enabled = true; enabled = true;

View File

@ -65,7 +65,7 @@ AudioOutput::CommandWait(Command cmd)
void void
AudioOutput::LockCommandWait(Command cmd) AudioOutput::LockCommandWait(Command cmd)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CommandWait(cmd); CommandWait(cmd);
} }
@ -162,7 +162,7 @@ AudioOutput::LockUpdate(const AudioFormat audio_format,
const MusicPipe &mp, const MusicPipe &mp,
bool force) bool force)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (enabled && really_enabled) { if (enabled && really_enabled) {
if (force || !fail_timer.IsDefined() || if (force || !fail_timer.IsDefined() ||
@ -178,7 +178,7 @@ AudioOutput::LockUpdate(const AudioFormat audio_format,
void void
AudioOutput::LockPlay() AudioOutput::LockPlay()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
@ -197,7 +197,7 @@ AudioOutput::LockPauseAsync()
mixer_auto_close()) */ mixer_auto_close()) */
mixer_auto_close(mixer); mixer_auto_close(mixer);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
@ -207,7 +207,7 @@ AudioOutput::LockPauseAsync()
void void
AudioOutput::LockDrainAsync() AudioOutput::LockDrainAsync()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(allow_play); assert(allow_play);
if (IsOpen()) if (IsOpen())
@ -217,7 +217,7 @@ AudioOutput::LockDrainAsync()
void void
AudioOutput::LockCancelAsync() AudioOutput::LockCancelAsync()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (IsOpen()) { if (IsOpen()) {
allow_play = false; allow_play = false;
@ -228,7 +228,7 @@ AudioOutput::LockCancelAsync()
void void
AudioOutput::LockAllowPlay() AudioOutput::LockAllowPlay()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
allow_play = true; allow_play = true;
if (IsOpen()) if (IsOpen())
@ -249,7 +249,7 @@ AudioOutput::LockCloseWait()
{ {
assert(!open || !fail_timer.IsDefined()); assert(!open || !fail_timer.IsDefined());
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CloseWait(); CloseWait();
} }
@ -270,7 +270,7 @@ AudioOutput::BeginDestroy()
mixer_auto_close(mixer); mixer_auto_close(mixer);
if (thread.IsDefined()) { if (thread.IsDefined()) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CommandAsync(Command::KILL); CommandAsync(Command::KILL);
} }
} }

View File

@ -43,7 +43,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 AudioOutput &ao = outputs.Get(i); const AudioOutput &ao = outputs.Get(i);
const ScopeLock lock(ao.mutex); const std::lock_guard<Mutex> lock(ao.mutex);
os.Format(AUDIO_DEVICE_STATE "%d:%s\n", os.Format(AUDIO_DEVICE_STATE "%d:%s\n",
ao.IsEnabled(), ao.GetName()); ao.IsEnabled(), ao.GetName());

View File

@ -397,7 +397,7 @@ AudioOutput::Task()
SetThreadTimerSlackUS(100); SetThreadTimerSlackUS(100);
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
while (true) { while (true) {
switch (command) { switch (command) {

View File

@ -92,7 +92,7 @@ RoarOutput::RoarOutput(const ConfigBlock &block)
inline int inline int
RoarOutput::GetVolume() const RoarOutput::GetVolume() const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (vss == nullptr || !alive) if (vss == nullptr || !alive)
return -1; return -1;
@ -116,7 +116,7 @@ RoarOutput::SetVolume(unsigned volume)
{ {
assert(volume <= 100); assert(volume <= 100);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (vss == nullptr || !alive) if (vss == nullptr || !alive)
throw std::runtime_error("closed"); throw std::runtime_error("closed");
@ -177,7 +177,7 @@ roar_use_audio_format(struct roar_audio_info *info,
inline void inline void
RoarOutput::Open(AudioFormat &audio_format) RoarOutput::Open(AudioFormat &audio_format)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (roar_simple_connect(&con, if (roar_simple_connect(&con,
host.empty() ? nullptr : host.c_str(), host.empty() ? nullptr : host.c_str(),
@ -201,7 +201,7 @@ RoarOutput::Open(AudioFormat &audio_format)
inline void inline void
RoarOutput::Close() RoarOutput::Close()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
alive = false; alive = false;
@ -214,7 +214,7 @@ RoarOutput::Close()
inline void inline void
RoarOutput::Cancel() RoarOutput::Cancel()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (vss == nullptr) if (vss == nullptr)
return; return;
@ -306,7 +306,7 @@ RoarOutput::SendTag(const Tag &tag)
if (vss == nullptr) if (vss == nullptr)
return; return;
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
size_t cnt = 0; size_t cnt = 0;
struct roar_keyval vals[32]; struct roar_keyval vals[32];

View File

@ -56,7 +56,7 @@ HttpdClient::Close()
void void
HttpdClient::LockClose() HttpdClient::LockClose()
{ {
const ScopeLock protect(httpd.mutex); const std::lock_guard<Mutex> protect(httpd.mutex);
Close(); Close();
} }
@ -272,7 +272,7 @@ HttpdClient::GetBytesTillMetaData() const
inline bool inline bool
HttpdClient::TryWrite() HttpdClient::TryWrite()
{ {
const ScopeLock protect(httpd.mutex); const std::lock_guard<Mutex> protect(httpd.mutex);
assert(state == RESPONSE); assert(state == RESPONSE);

View File

@ -200,7 +200,7 @@ public:
*/ */
gcc_pure gcc_pure
bool LockHasClients() const { bool LockHasClients() const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return HasClients(); return HasClients();
} }

View File

@ -153,7 +153,7 @@ HttpdOutput::RunDeferred()
/* 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 ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) { while (!pages.empty()) {
Page *page = pages.front(); Page *page = pages.front();
@ -200,7 +200,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
(void)address; (void)address;
#endif /* HAVE_WRAP */ #endif /* HAVE_WRAP */
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (fd >= 0) { if (fd >= 0) {
/* can we allow additional client */ /* can we allow additional client */
@ -296,7 +296,7 @@ httpd_output_open(AudioOutput *ao, AudioFormat &audio_format)
{ {
HttpdOutput *httpd = HttpdOutput::Cast(ao); HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex); const std::lock_guard<Mutex> protect(httpd->mutex);
httpd->Open(audio_format); httpd->Open(audio_format);
} }
@ -324,7 +324,7 @@ httpd_output_close(AudioOutput *ao)
{ {
HttpdOutput *httpd = HttpdOutput::Cast(ao); HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex); const std::lock_guard<Mutex> protect(httpd->mutex);
httpd->Close(); httpd->Close();
} }
@ -496,7 +496,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 ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
for (auto &client : clients) for (auto &client : clients)
client.PushMetaData(metadata); client.PushMetaData(metadata);
} }
@ -514,7 +514,7 @@ httpd_output_tag(AudioOutput *ao, const Tag &tag)
inline void inline void
HttpdOutput::CancelAllClients() HttpdOutput::CancelAllClients()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) { while (!pages.empty()) {
Page *page = pages.front(); Page *page = pages.front();

View File

@ -319,7 +319,7 @@ SlesOutput::Play(const void *chunk, size_t size)
pause = false; pause = false;
} }
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
@ -348,7 +348,7 @@ SlesOutput::Play(const void *chunk, size_t size)
inline void inline void
SlesOutput::Drain() SlesOutput::Drain()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(filled < BUFFER_SIZE); assert(filled < BUFFER_SIZE);
@ -371,7 +371,7 @@ SlesOutput::Cancel()
FormatWarning(sles_domain, FormatWarning(sles_domain,
"AndroidSimpleBufferQueue.Clear() failed"); "AndroidSimpleBufferQueue.Clear() failed");
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
n_queued = 0; n_queued = 0;
filled = 0; filled = 0;
} }
@ -398,7 +398,7 @@ SlesOutput::Pause()
inline void inline void
SlesOutput::PlayedCallback() SlesOutput::PlayedCallback()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
assert(n_queued > 0); assert(n_queued > 0);
--n_queued; --n_queued;
cond.signal(); cond.signal();

View File

@ -64,7 +64,7 @@ PlayerControl::Play(DetachedSong *song)
{ {
assert(song != nullptr); assert(song != nullptr);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
SeekLocked(song, SongTime::zero()); SeekLocked(song, SongTime::zero());
if (state == PlayerState::PAUSE) if (state == PlayerState::PAUSE)
@ -118,14 +118,14 @@ PlayerControl::PauseLocked()
void void
PlayerControl::LockPause() PlayerControl::LockPause()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
PauseLocked(); PauseLocked();
} }
void void
PlayerControl::LockSetPause(bool pause_flag) PlayerControl::LockSetPause(bool pause_flag)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
switch (state) { switch (state) {
case PlayerState::STOP: case PlayerState::STOP:
@ -146,7 +146,7 @@ PlayerControl::LockSetPause(bool pause_flag)
void void
PlayerControl::LockSetBorderPause(bool _border_pause) PlayerControl::LockSetBorderPause(bool _border_pause)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
border_pause = _border_pause; border_pause = _border_pause;
} }
@ -155,7 +155,7 @@ PlayerControl::LockGetStatus()
{ {
player_status status; player_status status;
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
SynchronousCommand(PlayerCommand::REFRESH); SynchronousCommand(PlayerCommand::REFRESH);
status.state = state; status.state = state;
@ -183,14 +183,14 @@ PlayerControl::SetError(PlayerError type, std::exception_ptr &&_error)
void void
PlayerControl::LockClearError() PlayerControl::LockClearError()
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ClearError(); ClearError();
} }
void void
PlayerControl::LockSetTaggedSong(const DetachedSong &song) PlayerControl::LockSetTaggedSong(const DetachedSong &song)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
delete tagged_song; delete tagged_song;
tagged_song = new DetachedSong(song); tagged_song = new DetachedSong(song);
} }
@ -207,7 +207,7 @@ PlayerControl::LockEnqueueSong(DetachedSong *song)
{ {
assert(song != nullptr); assert(song != nullptr);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
EnqueueSongLocked(song); EnqueueSongLocked(song);
} }
@ -246,7 +246,7 @@ PlayerControl::LockSeek(DetachedSong *song, SongTime t)
assert(song != nullptr); assert(song != nullptr);
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
SeekLocked(song, t); SeekLocked(song, t);
} }

View File

@ -224,7 +224,7 @@ struct PlayerControl final : AudioOutputClient {
* this function. * this function.
*/ */
void LockSignal() { void LockSignal() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
Signal(); Signal();
} }
@ -277,7 +277,7 @@ struct PlayerControl final : AudioOutputClient {
} }
void LockCommandFinished() { void LockCommandFinished() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CommandFinished(); CommandFinished();
} }
@ -294,7 +294,7 @@ struct PlayerControl final : AudioOutputClient {
bool WaitOutputConsumed(unsigned threshold); bool WaitOutputConsumed(unsigned threshold);
bool LockWaitOutputConsumed(unsigned threshold) { bool LockWaitOutputConsumed(unsigned threshold) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return WaitOutputConsumed(threshold); return WaitOutputConsumed(threshold);
} }
@ -333,7 +333,7 @@ private:
* object. * object.
*/ */
void LockSynchronousCommand(PlayerCommand cmd) { void LockSynchronousCommand(PlayerCommand cmd) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
SynchronousCommand(cmd); SynchronousCommand(cmd);
} }
@ -376,7 +376,7 @@ public:
} }
bool LockApplyBorderPause() { bool LockApplyBorderPause() {
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
return ApplyBorderPause(); return ApplyBorderPause();
} }
@ -410,7 +410,7 @@ public:
} }
void LockSetOutputError(std::exception_ptr &&_error) { void LockSetOutputError(std::exception_ptr &&_error) {
const ScopeLock lock(mutex); const std::lock_guard<Mutex> lock(mutex);
SetOutputError(std::move(_error)); SetOutputError(std::move(_error));
} }
@ -429,7 +429,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 ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
CheckRethrowError(); CheckRethrowError();
} }
@ -462,7 +462,7 @@ public:
* Like ReadTaggedSong(), but locks and unlocks the object. * Like ReadTaggedSong(), but locks and unlocks the object.
*/ */
DetachedSong *LockReadTaggedSong() { DetachedSong *LockReadTaggedSong() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return ReadTaggedSong(); return ReadTaggedSong();
} }
@ -521,7 +521,7 @@ public:
} }
void LockSetReplayGainMode(ReplayGainMode _mode) { void LockSetReplayGainMode(ReplayGainMode _mode) {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
replay_gain_mode = _mode; replay_gain_mode = _mode;
} }

View File

@ -213,7 +213,7 @@ private:
* allowed to be used while a command is being handled. * allowed to be used while a command is being handled.
*/ */
bool WaitDecoderStartup() { bool WaitDecoderStartup() {
const ScopeLock lock(pc.mutex); const std::lock_guard<Mutex> lock(pc.mutex);
while (decoder_starting) { while (decoder_starting) {
if (!CheckDecoderStartup()) { if (!CheckDecoderStartup()) {
@ -351,7 +351,7 @@ Player::StartDecoder(MusicPipe &_pipe)
{ {
/* copy ReplayGain parameters to the decoder */ /* copy ReplayGain parameters to the decoder */
const ScopeLock protect(pc.mutex); const std::lock_guard<Mutex> protect(pc.mutex);
dc.replay_gain_mode = pc.replay_gain_mode; dc.replay_gain_mode = pc.replay_gain_mode;
} }
@ -406,7 +406,7 @@ Player::ActivateDecoder()
queued = false; queued = false;
{ {
const ScopeLock lock(pc.mutex); const std::lock_guard<Mutex> lock(pc.mutex);
pc.ClearTaggedSong(); pc.ClearTaggedSong();
@ -787,7 +787,7 @@ play_chunk(PlayerControl &pc,
} }
{ {
const ScopeLock lock(pc.mutex); const std::lock_guard<Mutex> lock(pc.mutex);
pc.bit_rate = chunk->bit_rate; pc.bit_rate = chunk->bit_rate;
} }
@ -863,7 +863,7 @@ Player::PlayNextChunk()
} else { } else {
/* there are not enough decoded chunks yet */ /* there are not enough decoded chunks yet */
const ScopeLock lock(pc.mutex); const std::lock_guard<Mutex> lock(pc.mutex);
if (dc.IsIdle()) { if (dc.IsIdle()) {
/* the decoder isn't running, abort /* the decoder isn't running, abort
@ -911,7 +911,7 @@ Player::PlayNextChunk()
return false; return false;
} }
const ScopeLock lock(pc.mutex); const std::lock_guard<Mutex> lock(pc.mutex);
/* this formula should prevent that the decoder gets woken up /* this formula should prevent that the decoder gets woken up
with each chunk; it is more efficient to make it decode a with each chunk; it is more efficient to make it decode a

View File

@ -232,7 +232,7 @@ soundcloud_parse_json(const char *url, yajl_handle hand,
try { try {
auto input_stream = InputStream::OpenReady(url, mutex, cond); auto input_stream = InputStream::OpenReady(url, mutex, cond);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
yajl_status stat; yajl_status stat;
bool done = false; bool done = false;

View File

@ -213,7 +213,7 @@ CompositeStorage::~CompositeStorage()
Storage * Storage *
CompositeStorage::GetMount(const char *uri) CompositeStorage::GetMount(const char *uri)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto result = FindStorage(uri); auto result = FindStorage(uri);
if (*result.uri != 0) if (*result.uri != 0)
@ -226,7 +226,7 @@ CompositeStorage::GetMount(const char *uri)
void void
CompositeStorage::Mount(const char *uri, Storage *storage) CompositeStorage::Mount(const char *uri, Storage *storage)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
Directory &directory = root.Make(uri); Directory &directory = root.Make(uri);
if (directory.storage != nullptr) if (directory.storage != nullptr)
@ -237,7 +237,7 @@ CompositeStorage::Mount(const char *uri, Storage *storage)
bool bool
CompositeStorage::Unmount(const char *uri) CompositeStorage::Unmount(const char *uri)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
return root.Unmount(uri); return root.Unmount(uri);
} }
@ -266,7 +266,7 @@ CompositeStorage::FindStorage(const char *uri) const
StorageFileInfo StorageFileInfo
CompositeStorage::GetInfo(const char *uri, bool follow) CompositeStorage::GetInfo(const char *uri, bool follow)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
std::exception_ptr error; std::exception_ptr error;
@ -298,7 +298,7 @@ CompositeStorage::GetInfo(const char *uri, bool follow)
StorageDirectoryReader * StorageDirectoryReader *
CompositeStorage::OpenDirectory(const char *uri) CompositeStorage::OpenDirectory(const char *uri)
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
const Directory *directory = f.directory->Find(f.uri); const Directory *directory = f.directory->Find(f.uri);
@ -324,7 +324,7 @@ CompositeStorage::OpenDirectory(const char *uri)
std::string std::string
CompositeStorage::MapUTF8(const char *uri) const CompositeStorage::MapUTF8(const char *uri) const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
@ -336,7 +336,7 @@ CompositeStorage::MapUTF8(const char *uri) const
AllocatedPath AllocatedPath
CompositeStorage::MapFS(const char *uri) const CompositeStorage::MapFS(const char *uri) const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
@ -348,7 +348,7 @@ CompositeStorage::MapFS(const char *uri) const
const char * const char *
CompositeStorage::MapToRelativeUTF8(const char *uri) const CompositeStorage::MapToRelativeUTF8(const char *uri) const
{ {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
if (root.storage != nullptr) { if (root.storage != nullptr) {
const char *result = root.storage->MapToRelativeUTF8(uri); const char *result = root.storage->MapToRelativeUTF8(uri);

View File

@ -110,7 +110,7 @@ public:
*/ */
template<typename T> template<typename T>
void VisitMounts(T t) const { void VisitMounts(T t) const {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
std::string uri; std::string uri;
VisitMounts(uri, root, t); VisitMounts(uri, root, t);
} }

View File

@ -133,7 +133,7 @@ private:
void SetState(State _state) { void SetState(State _state) {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
state = _state; state = _state;
cond.broadcast(); cond.broadcast();
} }
@ -141,7 +141,7 @@ private:
void SetState(State _state, std::exception_ptr &&e) { void SetState(State _state, std::exception_ptr &&e) {
assert(GetEventLoop().IsInside()); assert(GetEventLoop().IsInside());
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
state = _state; state = _state;
last_exception = std::move(e); last_exception = std::move(e);
cond.broadcast(); cond.broadcast();
@ -164,7 +164,7 @@ private:
} }
void WaitConnected() { void WaitConnected() {
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
while (true) { while (true) {
switch (state) { switch (state) {

View File

@ -97,7 +97,7 @@ GetInfo(const char *path)
struct stat st; struct stat st;
{ {
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
if (smbc_stat(path, &st) != 0) if (smbc_stat(path, &st) != 0)
throw MakeErrno("Failed to access file"); throw MakeErrno("Failed to access file");
} }
@ -132,7 +132,7 @@ SmbclientStorage::OpenDirectory(const char *uri_utf8)
int handle; int handle;
{ {
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
handle = smbc_opendir(mapped.c_str()); handle = smbc_opendir(mapped.c_str());
if (handle < 0) if (handle < 0)
throw MakeErrno("Failed to open directory"); throw MakeErrno("Failed to open directory");
@ -160,7 +160,7 @@ SmbclientDirectoryReader::~SmbclientDirectoryReader()
const char * const char *
SmbclientDirectoryReader::Read() SmbclientDirectoryReader::Read()
{ {
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
struct smbc_dirent *e; struct smbc_dirent *e;
while ((e = smbc_readdir(handle)) != nullptr) { while ((e = smbc_readdir(handle)) != nullptr) {
@ -187,7 +187,7 @@ CreateSmbclientStorageURI(gcc_unused EventLoop &event_loop, const char *base)
SmbclientInit(); SmbclientInit();
const ScopeLock protect(smbclient_mutex); const std::lock_guard<Mutex> protect(smbclient_mutex);
SMBCCTX *ctx = smbc_new_context(); SMBCCTX *ctx = smbc_new_context();
if (ctx == nullptr) if (ctx == nullptr)
throw MakeErrno("smbc_new_context() failed"); throw MakeErrno("smbc_new_context() failed");

View File

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

View File

@ -210,7 +210,7 @@ try {
UniqueId3Tag UniqueId3Tag
tag_id3_load(InputStream &is) tag_id3_load(InputStream &is)
try { try {
const ScopeLock protect(is.mutex); const std::lock_guard<Mutex> protect(is.mutex);
auto tag = tag_id3_find_from_beginning(is); auto tag = tag_id3_find_from_beginning(is);
if (tag == nullptr && is.CheapSeeking()) { if (tag == nullptr && is.CheapSeeking()) {

View File

@ -44,8 +44,6 @@ class Mutex : public PosixMutex {};
#endif #endif
using ScopeLock = std::lock_guard<Mutex>;
/** /**
* Within the scope of an instance, this class will keep a #Mutex * Within the scope of an instance, this class will keep a #Mutex
* unlocked. * unlocked.

View File

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

View File

@ -50,7 +50,7 @@ tag_save(FILE *file, const Tag &tag)
static int static int
dump_input_stream(InputStream *is) dump_input_stream(InputStream *is)
{ {
const ScopeLock protect(is->mutex); const std::lock_guard<Mutex> protect(is->mutex);
/* print meta data */ /* print meta data */

View File

@ -65,7 +65,7 @@ public:
CPPUNIT_ASSERT(ris != sis); CPPUNIT_ASSERT(ris != sis);
CPPUNIT_ASSERT(ris != nullptr); CPPUNIT_ASSERT(ris != nullptr);
const ScopeLock protect(mutex); const std::lock_guard<Mutex> protect(mutex);
ris->Update(); ris->Update();
CPPUNIT_ASSERT(ris->IsReady()); CPPUNIT_ASSERT(ris->IsReady());