Commit b51bae55 authored by Max Kellermann's avatar Max Kellermann

thread/*Cond: rename methods to match std::condition_variable

parent 5bc8cd0e
......@@ -67,7 +67,7 @@ protected:
void CancelThread() noexcept override {
const std::lock_guard<Mutex> lock(mutex);
cancel = true;
cond.signal();
cond.notify_one();
}
private:
......@@ -87,11 +87,11 @@ private:
/* virtual methods from class InputStreamHandler */
void OnInputStreamReady() noexcept override {
cond.signal();
cond.notify_one();
}
void OnInputStreamAvailable() noexcept override {
cond.signal();
cond.notify_one();
}
};
......
......@@ -127,7 +127,7 @@ DecoderBridge::FlushChunk() noexcept
const std::lock_guard<Mutex> protect(dc.mutex);
if (dc.client_is_waiting)
dc.client_cond.signal();
dc.client_cond.notify_one();
}
bool
......@@ -310,7 +310,7 @@ DecoderBridge::CommandFinished() noexcept
}
dc.command = DecoderCommand::NONE;
dc.client_cond.signal();
dc.client_cond.notify_one();
}
SongTime
......
......@@ -67,7 +67,7 @@ DecoderControl::SetReady(const AudioFormat audio_format,
total_time = _duration;
state = DecoderState::DECODE;
client_cond.signal();
client_cond.notify_one();
}
bool
......
......@@ -199,7 +199,7 @@ public:
* calling this function.
*/
void Signal() noexcept {
cond.signal();
cond.notify_one();
}
/**
......@@ -367,7 +367,7 @@ public:
assert(command != DecoderCommand::NONE);
command = DecoderCommand::NONE;
client_cond.signal();
client_cond.notify_one();
}
/**
......@@ -428,11 +428,11 @@ private:
/* virtual methods from class InputStreamHandler */
void OnInputStreamReady() noexcept override {
cond.signal();
cond.notify_one();
}
void OnInputStreamAvailable() noexcept override {
cond.signal();
cond.notify_one();
}
};
......
......@@ -450,7 +450,7 @@ decoder_run_song(DecoderControl &dc,
throw FormatRuntimeError("Failed to decode %s", error_uri);
}
dc.client_cond.signal();
dc.client_cond.notify_one();
}
/**
......@@ -479,7 +479,7 @@ try {
dc.state = DecoderState::ERROR;
dc.command = DecoderCommand::NONE;
dc.error = std::current_exception();
dc.client_cond.signal();
dc.client_cond.notify_one();
}
void
......
......@@ -73,7 +73,7 @@ private:
const std::lock_guard<Mutex> lock(mutex);
done = true;
cond.signal();
cond.notify_one();
}
};
......
......@@ -50,7 +50,7 @@ BufferedInputStream::~BufferedInputStream() noexcept
{
const std::lock_guard<Mutex> lock(mutex);
stop = true;
wake_cond.signal();
wake_cond.notify_one();
}
thread.Join();
......@@ -81,7 +81,7 @@ BufferedInputStream::Seek(offset_type new_offset)
seek_offset = new_offset;
seek = true;
wake_cond.signal();
wake_cond.notify_one();
while (seek)
client_cond.wait(mutex);
......@@ -123,21 +123,21 @@ BufferedInputStream::Read(void *ptr, size_t s)
if (!IsAvailable()) {
/* wake up the sleeping thread */
idle = false;
wake_cond.signal();
wake_cond.notify_one();
}
return nbytes;
}
if (read_error) {
wake_cond.signal();
wake_cond.notify_one();
std::rethrow_exception(std::exchange(read_error, {}));
}
if (idle) {
/* wake up the sleeping thread */
idle = false;
wake_cond.signal();
wake_cond.notify_one();
}
client_cond.wait(mutex);
......@@ -163,7 +163,7 @@ BufferedInputStream::RunThread() noexcept
idle = false;
seek = false;
client_cond.signal();
client_cond.notify_one();
} else if (!idle && !read_error &&
input->IsAvailable() && !input->IsEOF()) {
const auto read_offset = input->GetOffset();
......@@ -186,7 +186,7 @@ BufferedInputStream::RunThread() noexcept
input->Seek(offset);
} catch (...) {
read_error = std::current_exception();
client_cond.signal();
client_cond.notify_one();
InvokeOnAvailable();
}
}
......@@ -202,7 +202,7 @@ BufferedInputStream::RunThread() noexcept
read_error = std::current_exception();
}
client_cond.signal();
client_cond.notify_one();
InvokeOnAvailable();
} else
wake_cond.wait(mutex);
......
......@@ -99,7 +99,7 @@ public:
}
void OnInputStreamAvailable() noexcept override {
wake_cond.signal();
wake_cond.notify_one();
}
private:
......
......@@ -31,11 +31,11 @@ struct CondInputStreamHandler final : InputStreamHandler {
/* virtual methods from class InputStreamHandler */
void OnInputStreamReady() noexcept override {
cond.signal();
cond.notify_one();
}
void OnInputStreamAvailable() noexcept override {
cond.signal();
cond.notify_one();
}
};
......
......@@ -46,7 +46,7 @@ ProxyInputStream::SetInput(InputStreamPtr _input) noexcept
ready */
CopyAttributes();
set_input_cond.signal();
set_input_cond.notify_one();
}
void
......
......@@ -46,7 +46,7 @@ ThreadInputStream::Stop() noexcept
{
const std::lock_guard<Mutex> lock(mutex);
close = true;
wake_cond.signal();
wake_cond.notify_one();
}
Cancel();
......@@ -145,7 +145,7 @@ ThreadInputStream::Read(void *ptr, size_t read_size)
size_t nbytes = std::min(read_size, r.size);
memcpy(ptr, r.data, nbytes);
buffer.Consume(nbytes);
wake_cond.broadcast();
wake_cond.notify_all();
offset += nbytes;
return nbytes;
}
......
......@@ -61,7 +61,7 @@ private:
bool LockWaitFinished() noexcept {
const std::lock_guard<Mutex> protect(mutex);
while (!finished)
if (!cond.timed_wait(mutex, timeout))
if (!cond.wait_for(mutex, timeout))
return false;
return true;
......@@ -74,7 +74,7 @@ private:
void LockSetFinished() noexcept {
const std::lock_guard<Mutex> protect(mutex);
finished = true;
cond.signal();
cond.notify_one();
}
/* virtual methods from NfsLease */
......
......@@ -97,7 +97,7 @@ SmbclientNeighborExplorer::Close() noexcept
{
const std::lock_guard<Mutex> lock(mutex);
quit = true;
cond.signal();
cond.notify_one();
}
thread.Join();
......@@ -247,7 +247,7 @@ SmbclientNeighborExplorer::ThreadFunc() noexcept
break;
// TODO: sleep for how long?
cond.timed_wait(mutex, std::chrono::seconds(10));
cond.wait_for(mutex, std::chrono::seconds(10));
}
}
......
......@@ -122,7 +122,7 @@ AudioOutputControl::CommandAsync(Command cmd) noexcept
assert(IsCommandFinished());
command = cmd;
wake_cond.signal();
wake_cond.notify_one();
}
void
......@@ -292,7 +292,7 @@ AudioOutputControl::LockPlay() noexcept
if (IsOpen() && !in_playback_loop && !woken_for_play) {
woken_for_play = true;
wake_cond.signal();
wake_cond.notify_one();
}
}
......@@ -340,7 +340,7 @@ AudioOutputControl::LockAllowPlay() noexcept
allow_play = true;
if (IsOpen())
wake_cond.signal();
wake_cond.notify_one();
}
void
......
......@@ -39,7 +39,7 @@ AudioOutputControl::CommandFinished() noexcept
assert(command != Command::NONE);
command = Command::NONE;
client_cond.signal();
client_cond.notify_one();
}
inline void
......@@ -215,7 +215,7 @@ AudioOutputControl::WaitForDelay() noexcept
if (delay <= std::chrono::steady_clock::duration::zero())
return true;
(void)wake_cond.timed_wait(mutex, delay);
(void)wake_cond.wait_for(mutex, delay);
if (command != Command::NONE)
return false;
......
......@@ -305,7 +305,7 @@ private:
const std::lock_guard<Mutex> lock(mutex);
/* notify the OutputThread that there is now
room in ring_buffer */
cond.signal();
cond.notify_one();
return true;
}
......@@ -330,7 +330,7 @@ private:
const std::lock_guard<Mutex> lock(mutex);
error = std::current_exception();
active = false;
cond.signal();
cond.notify_one();
}
/* virtual methods from class MultiSocketMonitor */
......@@ -956,7 +956,7 @@ try {
}
drain = false;
cond.signal();
cond.notify_one();
return;
}
}
......@@ -984,7 +984,7 @@ try {
{
const std::lock_guard<Mutex> lock(mutex);
active = false;
cond.signal();
cond.notify_one();
}
/* avoid race condition: see if data has
......
......@@ -120,7 +120,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept
/* wake up the client that may be waiting for the queue to be
flushed */
cond.broadcast();
cond.notify_all();
}
void
......@@ -398,7 +398,7 @@ HttpdOutput::CancelAllClients() noexcept
for (auto &client : clients)
client.CancelQueue();
cond.broadcast();
cond.notify_all();
}
void
......
......@@ -397,7 +397,7 @@ SlesOutput::PlayedCallback()
const std::lock_guard<Mutex> protect(mutex);
assert(n_queued > 0);
--n_queued;
cond.signal();
cond.notify_one();
}
static bool
......
......@@ -351,7 +351,7 @@ private:
* calling this function.
*/
void Signal() noexcept {
cond.signal();
cond.notify_one();
}
/**
......@@ -382,7 +382,7 @@ private:
void ClientSignal() noexcept {
assert(thread.IsInside());
client_cond.signal();
client_cond.notify_one();
}
/**
......
......@@ -138,7 +138,7 @@ protected:
request.Stop();
done = true;
cond.signal();
cond.notify_one();
}
void LockSetDone() {
......
......@@ -138,7 +138,7 @@ private:
const std::lock_guard<Mutex> protect(mutex);
state = _state;
cond.broadcast();
cond.notify_all();
}
void SetState(State _state, std::exception_ptr &&e) noexcept {
......@@ -147,7 +147,7 @@ private:
const std::lock_guard<Mutex> protect(mutex);
state = _state;
last_exception = std::move(e);
cond.broadcast();
cond.notify_all();
}
void Connect() noexcept {
......
......@@ -147,7 +147,7 @@ UdisksStorage::SetMountPoint(Path mount_point)
mount_error = {};
want_mount = false;
cond.broadcast();
cond.notify_all();
}
void
......@@ -188,7 +188,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
const std::lock_guard<Mutex> lock(mutex);
mount_error = std::current_exception();
want_mount = false;
cond.broadcast();
cond.notify_all();
return;
}
......@@ -247,7 +247,7 @@ try {
const std::lock_guard<Mutex> lock(mutex);
mount_error = std::current_exception();
want_mount = false;
cond.broadcast();
cond.notify_all();
}
void
......@@ -266,7 +266,7 @@ try {
const std::lock_guard<Mutex> lock(mutex);
mount_error = std::current_exception();
want_mount = false;
cond.broadcast();
cond.notify_all();
}
void
......@@ -306,7 +306,7 @@ try {
const std::lock_guard<Mutex> lock(mutex);
mount_error = std::current_exception();
mounted_storage.reset();
cond.broadcast();
cond.notify_all();
}
void
......@@ -318,12 +318,12 @@ try {
const std::lock_guard<Mutex> lock(mutex);
mount_error = {};
mounted_storage.reset();
cond.broadcast();
cond.notify_all();
} catch (...) {
const std::lock_guard<Mutex> lock(mutex);
mount_error = std::current_exception();
mounted_storage.reset();
cond.broadcast();
cond.notify_all();
}
std::string
......
/*
* Copyright (C) 2009-2015 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2009-2019 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -62,11 +62,11 @@ public:
PosixCond(const PosixCond &other) = delete;
PosixCond &operator=(const PosixCond &other) = delete;
void signal() noexcept {
void notify_one() noexcept {
pthread_cond_signal(&cond);
}
void broadcast() noexcept {
void notify_all() noexcept {
pthread_cond_broadcast(&cond);
}
......@@ -75,7 +75,7 @@ public:
}
private:
bool timed_wait(PosixMutex &mutex, uint_least32_t timeout_us) noexcept {
bool wait_for(PosixMutex &mutex, uint_least32_t timeout_us) noexcept {
struct timeval now;
gettimeofday(&now, nullptr);
......@@ -92,15 +92,15 @@ private:
}
public:
bool timed_wait(PosixMutex &mutex,
std::chrono::steady_clock::duration timeout) noexcept {
bool wait_for(PosixMutex &mutex,
std::chrono::steady_clock::duration timeout) noexcept {
auto timeout_us = std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
if (timeout_us < 0)
timeout_us = 0;
else if (timeout_us > std::numeric_limits<uint_least32_t>::max())
timeout_us = std::numeric_limits<uint_least32_t>::max();
return timed_wait(mutex, timeout_us);
return wait_for(mutex, timeout_us);
}
};
......
/*
* Copyright (C) 2009-2013 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2009-2019 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -48,29 +48,29 @@ public:
WindowsCond(const WindowsCond &other) = delete;
WindowsCond &operator=(const WindowsCond &other) = delete;
void signal() noexcept {
void notify_one() noexcept {
WakeConditionVariable(&cond);
}
void broadcast() noexcept {
void notify_all() noexcept {
WakeAllConditionVariable(&cond);
}
private:
bool timed_wait(CriticalSection &mutex, DWORD timeout_ms) noexcept {
bool wait_for(CriticalSection &mutex, DWORD timeout_ms) noexcept {
return SleepConditionVariableCS(&cond, &mutex.critical_section,
timeout_ms);
}
public:
bool timed_wait(CriticalSection &mutex,
std::chrono::steady_clock::duration timeout) noexcept {
bool wait_for(CriticalSection &mutex,
std::chrono::steady_clock::duration timeout) noexcept {
auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count();
return timed_wait(mutex, timeout_ms);
return wait_for(mutex, timeout_ms);
}
void wait(CriticalSection &mutex) noexcept {
timed_wait(mutex, INFINITE);
wait_for(mutex, INFINITE);
}
};
......
......@@ -190,14 +190,14 @@ public:
const std::lock_guard<Mutex> lock(mutex);
tag = std::move(_tag);
done = true;
cond.broadcast();
cond.notify_all();
}
void OnRemoteTagError(std::exception_ptr e) noexcept override {
const std::lock_guard<Mutex> lock(mutex);
error = std::move(e);
done = true;
cond.broadcast();
cond.notify_all();
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment