CppCommon  1.0.4.1
C++ Common Library
condition_variable.inl
Go to the documentation of this file.
1 
9 namespace CppCommon {
10 
11 template <typename TPredicate>
12 void ConditionVariable::Wait(CriticalSection& cs, TPredicate predicate)
13 {
14  while (!predicate())
15  Wait(cs);
16 }
17 
18 template <typename TPredicate>
19 bool ConditionVariable::TryWaitFor(CriticalSection& cs, const Timespan& timespan, TPredicate predicate)
20 {
21  Timestamp timeout = UtcTimestamp() + timespan;
22  while (!predicate())
23  if (!TryWaitFor(cs, timeout - UtcTimestamp()))
24  return predicate();
25  return true;
26 }
27 
28 } // namespace CppCommon
bool TryWaitFor(CriticalSection &cs, const Timespan &timespan)
Try to wait for the given timespan until condition variable is notified.
void Wait(CriticalSection &cs)
Wait until condition variable is notified.
Critical section synchronization primitive.
UTC timestamp.
Definition: timestamp.h:248
C++ Common project definitions.
Definition: token_bucket.h:15