folly::HHWheelTimerBase

Hashed Hierarchical Wheel Timer

Synopsis

Declared in <folly/io/async/HHWheelTimer.h>

template<class Duration>
class HHWheelTimerBase
    : public folly::DelayedDestruction

Description

We model timers as the number of ticks until the next due event. We allow 32-bits of space to track this due interval, and break that into 4 regions of 8 bits. Each region indexes into a bucket of 256 lists.

Bucket 0 represents those events that are due the soonest. Each tick causes us to look at the next list in a bucket. The 0th list in a bucket is special; it means that it is time to flush the timers from the next higher bucket and schedule them into a different bucket.

This technique results in a very cheap mechanism for maintaining time and timers.

Unlike the original timer wheel paper, this implementation does not tick constantly, and instead calculates the exact next wakeup time.

Base Classes

NameDescription
folly::DelayedDestructionDelayedDestruction is a helper class to ensure objects are not deleted while they still have functions executing in a higher stack frame.

Types

NameDescription
Callback A callback to be notified when a timeout has expired.
Destructor Helper class to allow DelayedDestruction classes to be used with std::shared_ptr.
DestructorGuard Classes should create a DestructorGuard object on the stack in any function that may invoke callback functions.
IntrusivePtr This smart pointer is a convenient way to manage a concrete DelayedDestructorBase child. It can replace the equivalent raw pointer and provide automatic memory management.

Type Aliases

NameDescription
SharedPtr Shared pointer to a timer.
UniquePtr Unique pointer that destroys the timer via DelayedDestruction.

Member Functions

NameDescription
HHWheelTimerBase [constructor]Create a new HHWheelTimerBase with the specified interval and the default timeout value set.
operator= [deleted]Deleted copy assignment operator.
cancelAll Cancel all outstanding timeouts
count Return the number of currently pending timeouts
destroy [virtual]destroy() requests destruction of the object.
getDefaultTimeout Get the default timeout interval for this HHWheelTimerBase.
getDestroyPending Returns whether destruction has been requested but deferred.
getTickInterval Get the tick interval for this HHWheelTimerBase.
isDetachable Returns whether the timer can be detached from its event base.
scheduleTimeout scheduleTimeout overloads
scheduleTimeoutFn Schedule a callable to be invoked after the specified timeout interval.
setDefaultTimeout Set the default timeout interval for this HHWheelTimerBase.

Static Member Functions

NameDescription
newTimer Creates a new timer wrapped in a UniquePtr.

Static Data Members

NameDescription
DEFAULT_TICK_INTERVAL Default tick interval, in the timer's duration units.

Using Declarations

NameDescription
attachEventBase Attaches the timer to an EventBase.
detachEventBase Detaches the timer from its EventBase.
getTimeoutManager Returns the TimeoutManager driving the timer.

Protected Member Functions

NameDescription
~HHWheelTimerBase [destructor] [virtual]Protected destructor.
getDestructorGuardCount Get the number of DestructorGuards currently protecting this object.
onDelayedDestroy [virtual]Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed.

Specializations

Name
HHWheelTimerBase<std::chrono::microseconds>
HHWheelTimerBase<std::chrono::milliseconds>