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.thread.IsDefined());
const ScopeLock protect(io.mutex);
const std::lock_guard<Mutex> protect(io.mutex);
io.thread.Start(io_thread_func, nullptr);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -228,7 +228,7 @@ struct DecoderControl {
gcc_pure
bool LockIsIdle() const {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
return IsIdle();
}
@ -238,7 +238,7 @@ struct DecoderControl {
gcc_pure
bool LockIsStarting() const {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
return IsStarting();
}
@ -250,7 +250,7 @@ struct DecoderControl {
gcc_pure
bool LockHasFailed() const {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
return HasFailed();
}
@ -281,7 +281,7 @@ struct DecoderControl {
* Like CheckRethrowError(), but locks and unlocks the object.
*/
void LockCheckRethrowError() const {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
CheckRethrowError();
}
@ -309,7 +309,7 @@ struct DecoderControl {
gcc_pure
bool LockIsCurrentSong(const DetachedSong &_song) const {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
return IsCurrentSong(_song);
}
@ -346,13 +346,13 @@ private:
* object.
*/
void LockSynchronousCommand(DecoderCommand cmd) {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
ClearError();
SynchronousCommandLocked(cmd);
}
void LockAsynchronousCommand(DecoderCommand cmd) {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
command = cmd;
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
will be available then */
const ScopeLock protect(dc.mutex);
const std::lock_guard<Mutex> protect(dc.mutex);
is->Update();
while (!is->IsReady()) {
@ -264,7 +264,7 @@ static void
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)
/* ReplayGain is disabled */
return;
@ -288,7 +288,7 @@ decoder_run_stream(DecoderBridge &bridge, const char *uri)
MaybeLoadReplayGain(bridge, *input_stream);
const ScopeLock protect(dc.mutex);
const std::lock_guard<Mutex> protect(dc.mutex);
bool tried = false;
return dc.command == DecoderCommand::STOP ||
@ -318,10 +318,10 @@ TryDecoderFile(DecoderBridge &bridge, Path path_fs, const char *suffix,
DecoderControl &dc = bridge.dc;
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);
} 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);
} else
return false;
@ -344,7 +344,7 @@ TryContainerDecoder(DecoderBridge &bridge, Path path_fs, const char *suffix,
bridge.error = nullptr;
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);
}
@ -517,7 +517,7 @@ decoder_task(void *arg)
SetThreadName("decoder");
const ScopeLock protect(dc.mutex);
const std::lock_guard<Mutex> protect(dc.mutex);
do {
assert(dc.state == DecoderState::STOP ||

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -429,7 +429,7 @@ CurlInputStream::RequestDone(CURLcode result, long status)
FreeEasy();
AsyncInputStream::SetClosed();
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
if (result != CURLE_OK) {
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);
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
if (IsSeekPending())
SeekDone();

View File

@ -142,7 +142,7 @@ NfsInputStream::DoSeek(offset_type new_offset)
void
NfsInputStream::OnNfsFileOpen(uint64_t _size)
{
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
if (reconnecting) {
/* reconnect has succeeded */
@ -162,7 +162,7 @@ NfsInputStream::OnNfsFileOpen(uint64_t _size)
void
NfsInputStream::OnNfsFileRead(const void *data, size_t data_size)
{
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
assert(!IsBufferFull());
assert(IsBufferFull() == (GetBufferSpace() == 0));
AppendToBuffer(data, data_size);
@ -175,7 +175,7 @@ NfsInputStream::OnNfsFileRead(const void *data, size_t data_size)
void
NfsInputStream::OnNfsFileError(std::exception_ptr &&e)
{
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
if (IsPaused()) {
/* 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://"))
return nullptr;
const ScopeLock protect(smbclient_mutex);
const std::lock_guard<Mutex> protect(smbclient_mutex);
SMBCCTX *ctx = smbc_new_context();
if (ctx == nullptr)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -153,7 +153,7 @@ HttpdOutput::RunDeferred()
/* this method runs in the IOThread; it broadcasts pages from
our own queue to all clients */
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) {
Page *page = pages.front();
@ -200,7 +200,7 @@ HttpdOutput::OnAccept(int fd, SocketAddress address, gcc_unused int uid)
(void)address;
#endif /* HAVE_WRAP */
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
if (fd >= 0) {
/* can we allow additional client */
@ -296,7 +296,7 @@ httpd_output_open(AudioOutput *ao, AudioFormat &audio_format)
{
HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex);
const std::lock_guard<Mutex> protect(httpd->mutex);
httpd->Open(audio_format);
}
@ -324,7 +324,7 @@ httpd_output_close(AudioOutput *ao)
{
HttpdOutput *httpd = HttpdOutput::Cast(ao);
const ScopeLock protect(httpd->mutex);
const std::lock_guard<Mutex> protect(httpd->mutex);
httpd->Close();
}
@ -496,7 +496,7 @@ HttpdOutput::SendTag(const Tag &tag)
metadata = icy_server_metadata_page(tag, &types[0]);
if (metadata != nullptr) {
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
for (auto &client : clients)
client.PushMetaData(metadata);
}
@ -514,7 +514,7 @@ httpd_output_tag(AudioOutput *ao, const Tag &tag)
inline void
HttpdOutput::CancelAllClients()
{
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
while (!pages.empty()) {
Page *page = pages.front();

View File

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

View File

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

View File

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

View File

@ -213,7 +213,7 @@ private:
* allowed to be used while a command is being handled.
*/
bool WaitDecoderStartup() {
const ScopeLock lock(pc.mutex);
const std::lock_guard<Mutex> lock(pc.mutex);
while (decoder_starting) {
if (!CheckDecoderStartup()) {
@ -351,7 +351,7 @@ Player::StartDecoder(MusicPipe &_pipe)
{
/* 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;
}
@ -406,7 +406,7 @@ Player::ActivateDecoder()
queued = false;
{
const ScopeLock lock(pc.mutex);
const std::lock_guard<Mutex> lock(pc.mutex);
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;
}
@ -863,7 +863,7 @@ Player::PlayNextChunk()
} else {
/* there are not enough decoded chunks yet */
const ScopeLock lock(pc.mutex);
const std::lock_guard<Mutex> lock(pc.mutex);
if (dc.IsIdle()) {
/* the decoder isn't running, abort
@ -911,7 +911,7 @@ Player::PlayNextChunk()
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
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 {
auto input_stream = InputStream::OpenReady(url, mutex, cond);
const ScopeLock protect(mutex);
const std::lock_guard<Mutex> protect(mutex);
yajl_status stat;
bool done = false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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