5#include <userver/engine/condition_variable_status.hpp>
6#include <userver/engine/deadline.hpp>
7#include <userver/engine/impl/wait_list_fwd.hpp>
10#include <userver/engine/task/task.hpp>
12USERVER_NAMESPACE_BEGIN
14namespace engine::impl {
16void OnConditionVariableSpuriousWakeup();
18template <
typename MutexType>
19class ConditionVariableAny {
21 ConditionVariableAny();
22 ~ConditionVariableAny();
24 ConditionVariableAny(
const ConditionVariableAny&) =
delete;
25 ConditionVariableAny(ConditionVariableAny&&) =
delete;
26 ConditionVariableAny& operator=(
const ConditionVariableAny&) =
delete;
27 ConditionVariableAny& operator=(ConditionVariableAny&&) =
delete;
29 CvStatus WaitUntil(std::unique_lock<MutexType>&, Deadline);
31 template <
typename Predicate>
32 bool WaitUntil(std::unique_lock<MutexType>&, Deadline, Predicate&&);
38 FastPimplWaitList waiters_;
41template <
typename MutexType>
42template <
typename Predicate>
43bool ConditionVariableAny<MutexType>::WaitUntil(
44 std::unique_lock<MutexType>& lock, Deadline deadline,
45 Predicate&& predicate) {
46 bool predicate_result = predicate();
48 while (!predicate_result && status ==
CvStatus::kNoTimeout) {
49 status = WaitUntil(lock, deadline);
50 predicate_result = predicate();
51 if (!predicate_result && status ==
CvStatus::kNoTimeout) {
52 impl::OnConditionVariableSpuriousWakeup();
55 return predicate_result;