class BlockingRefCount
Defined at line 47 of file ../../zircon/system/ulib/refcount/include/refcount/blocking_refcount.h
A BlockingRefCount provides a counter which can be incremented and
decremented, with an additional operation allowing threads to wait
for the count to become zero.
This can be useful in scenarios where an object is waiting for
in-flight callbacks to complete before cleaning up resources,
for example:
class MyClass {
void PerformAsyncOperation() {
// Increment the counter when we start the work, and decrement
// it when finished.
in_flight_ops_.Inc();
DoWork(..., /*completion_callback=*/[this](){
// ...
in_flight_ops_.Dec();
});
}
// Wait for all in-flight operations to terminate before
// destructing.
~MyClass() {
in_flight_ops_.WaitForZero();
}
BlockingRefCount in_flight_ops_;
}
BlockingRefCount must not be destructed while threads are waiting
on it.
Thread safe.
Public Methods
void BlockingRefCount ()
Create a new BlockingRefCount with initial reference count of 0.
Defined at line 13 of file ../../zircon/system/ulib/refcount/blocking_refcount.cc
void BlockingRefCount (int32_t initial_count)
Create a new BlockingRefCount with the given initial reference count.
Defined at line 15 of file ../../zircon/system/ulib/refcount/blocking_refcount.cc
void Inc ()
Increment the reference count.
Defined at line 19 of file ../../zircon/system/ulib/refcount/blocking_refcount.cc
void Dec ()
Decrement the reference count, potentially waking up threads waiting
for the count to reach zero.
Callers must ensure that calling this would not result in the counter
dropping below zero.
Defined at line 27 of file ../../zircon/system/ulib/refcount/blocking_refcount.cc
void WaitForZero ()
Wait for the counter to become zero.
If the counter only briefly becomes zero, waiting threads may not
see the zero and fail to wake up. If the counter hits zero and
remains, however, threads are guaranteed to wake up.
Defined at line 37 of file ../../zircon/system/ulib/refcount/blocking_refcount.cc