class CondVar

Defined at line 911 of file ../../third_party/abseil-cpp/absl/synchronization/mutex.h

-----------------------------------------------------------------------------

CondVar

-----------------------------------------------------------------------------

A condition variable, reflecting state evaluated separately outside of the

`Mutex` object, which can be signaled to wake callers.

This class is not normally needed; use `Mutex` member functions such as

`Mutex::Await()` and intrinsic `Condition` abstractions. In rare cases

with many threads and many conditions, `CondVar` may be faster.

The implementation may deliver signals to any condition variable at

any time, even when no call to `Signal()` or `SignalAll()` is made; as a

result, upon being awoken, you must check the logical condition you have

been waiting upon.

Examples:

Usage for a thread waiting for some condition C protected by mutex mu:

mu.Lock();

while (!C) { cv->Wait(

&mu

); } // releases and reacquires mu

// C holds; process data

mu.Unlock();

Usage to wake T is:

mu.Lock();

// process data, possibly establishing C

if (C) { cv->Signal(); }

mu.Unlock();

If C may be useful to more than one waiter, use `SignalAll()` instead of

`Signal()`.

With this implementation it is efficient to use `Signal()/SignalAll()` inside

the locked region; this usage can make reasoning about your program easier.

Public Methods

void Wait (Mutex * mu)

CondVar::Wait()

Atomically releases a `Mutex` and blocks on this condition variable.

Waits until awakened by a call to `Signal()` or `SignalAll()` (or a

spurious wakeup), then reacquires the `Mutex` and returns.

Requires and ensures that the current thread holds the `Mutex`.

Defined at line 924 of file ../../third_party/abseil-cpp/absl/synchronization/mutex.h

bool WaitWithTimeout (Mutex * mu, absl::Duration timeout)

CondVar::WaitWithTimeout()

Atomically releases a `Mutex` and blocks on this condition variable.

Waits until awakened by a call to `Signal()` or `SignalAll()` (or a

spurious wakeup), or until the timeout has expired, then reacquires

the `Mutex` and returns.

Returns true if the timeout has expired without this `CondVar`

being signalled in any manner. If both the timeout has expired

and this `CondVar` has been signalled, the implementation is free

to return `true` or `false`.

Requires and ensures that the current thread holds the `Mutex`.

Defined at line 941 of file ../../third_party/abseil-cpp/absl/synchronization/mutex.h

bool WaitWithDeadline (Mutex * mu, absl::Time deadline)

CondVar::WaitWithDeadline()

Atomically releases a `Mutex` and blocks on this condition variable.

Waits until awakened by a call to `Signal()` or `SignalAll()` (or a

spurious wakeup), or until the deadline has passed, then reacquires

the `Mutex` and returns.

Deadlines in the past are equivalent to an immediate deadline.

Returns true if the deadline has passed without this `CondVar`

being signalled in any manner. If both the deadline has passed

and this `CondVar` has been signalled, the implementation is free

to return `true` or `false`.

Requires and ensures that the current thread holds the `Mutex`.

Defined at line 960 of file ../../third_party/abseil-cpp/absl/synchronization/mutex.h

void CondVar ()

A `CondVar` allocated on the heap or on the stack can use the this

constructor.

Defined at line 1082 of file ../../third_party/abseil-cpp/absl/synchronization/mutex.h

void Signal ()

CondVar::Signal()

Signal this `CondVar`; wake at least one waiter if one exists.

void SignalAll ()

CondVar::SignalAll()

Signal this `CondVar`; wake all waiters.

void EnableDebugLog (const char * name)

CondVar::EnableDebugLog()

Causes all subsequent uses of this `CondVar` to be logged via

`ABSL_RAW_LOG(INFO)`. Log entries are tagged with `name` if `name != 0`.

Note: this method substantially reduces `CondVar` performance.