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