Commit 67cb8eed authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Facebook Github Bot

Allow cascading into the current tick

Summary:
Currently, when cascading, we are unable to use bucket 0. This means that timeouts that are already expired would need to wait another tick before being fired.

A simple example is when we're at tick 0 and scheduling for tick 256, such timeout would go into cascading logic and should fall into bucket 0 of next wheel epoch. However, the existing logic would cascade it to bucket 1.

This diff fixes that, by reordering draining of current bucket and cascading timeouts.

Reviewed By: yfeldblum

Differential Revision: D13541506

fbshipit-source-id: 1284fca18612ae91f96538192bfad75e27cd816c
parent c53bda78
......@@ -210,6 +210,14 @@ void HHWheelTimer::timeoutExpired() noexcept {
while (lastTick_ < nextTick) {
int idx = lastTick_ & WHEEL_MASK;
if (idx == 0) {
// Cascade timers
if (cascadeTimers(1, (lastTick_ >> WHEEL_BITS) & WHEEL_MASK) &&
cascadeTimers(2, (lastTick_ >> (2 * WHEEL_BITS)) & WHEEL_MASK)) {
cascadeTimers(3, (lastTick_ >> (3 * WHEEL_BITS)) & WHEEL_MASK);
}
}
auto bi = makeBitIterator(bitmap_.begin());
*(bi + idx) = false;
......@@ -220,14 +228,6 @@ void HHWheelTimer::timeoutExpired() noexcept {
cbs->pop_front();
timeoutsToRunNow_.push_back(*cb);
}
if (idx == 0) {
// Cascade timers
if (cascadeTimers(1, (lastTick_ >> WHEEL_BITS) & WHEEL_MASK) &&
cascadeTimers(2, (lastTick_ >> (2 * WHEEL_BITS)) & WHEEL_MASK)) {
cascadeTimers(3, (lastTick_ >> (3 * WHEEL_BITS)) & WHEEL_MASK);
}
}
}
while (!timeoutsToRunNow_.empty()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment