Added timeout to ConditionVariableNotifier::waitForNotification() function
This commit is contained in:
@@ -8,11 +8,18 @@ namespace Bloom
|
||||
this->conditionalVariable.notify_all();
|
||||
}
|
||||
|
||||
void ConditionVariableNotifier::waitForNotification() {
|
||||
auto lock = std::unique_lock(this->mutex);
|
||||
this->conditionalVariable.wait(lock, [this] {
|
||||
void ConditionVariableNotifier::waitForNotification(std::optional<std::chrono::milliseconds> timeout) {
|
||||
const auto predicate = [this] {
|
||||
return this->notified;
|
||||
});
|
||||
};
|
||||
auto lock = std::unique_lock(this->mutex);
|
||||
|
||||
if (timeout.has_value()) {
|
||||
this->conditionalVariable.wait_for(lock, timeout.value(), predicate);
|
||||
|
||||
} else {
|
||||
this->conditionalVariable.wait(lock, predicate);
|
||||
}
|
||||
|
||||
this->notified = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user