Commit b01aec06 authored by Haijun Zhu's avatar Haijun Zhu Committed by Dave Watson

Fix bug and unit test failure in HHWheelTimer

Summary: Some minor bug and a failed test caused by D1578466

Test Plan:
fbconfig thrift/lib/cpp/test:HHWheelTimerTest && fbmake
runtests

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, alandau, bmatheny, njormrod

FB internal diff: D1581949
parent 4833e0ef
......@@ -94,18 +94,18 @@ void HHWheelTimer::destroy() {
void HHWheelTimer::scheduleTimeoutImpl(Callback* callback,
std::chrono::milliseconds timeout) {
uint32_t due = timeToWheelTicks(timeout) + nextTick_;
int64_t due = timeToWheelTicks(timeout) + nextTick_;
int64_t diff = due - nextTick_;
CallbackList* list;
if (diff < WHEEL_SIZE) {
if (diff < 0) {
list = &buckets_[0][nextTick_ & WHEEL_MASK];
} else if (diff < WHEEL_SIZE) {
list = &buckets_[0][due & WHEEL_MASK];
} else if (diff < 1 << (2 * WHEEL_BITS)) {
list = &buckets_[1][(due >> WHEEL_BITS) & WHEEL_MASK];
} else if (diff < 1 << (3 * WHEEL_BITS)) {
list = &buckets_[2][(due >> 2 * WHEEL_BITS) & WHEEL_MASK];
} else if (diff < 0) {
list = &buckets_[0][nextTick_ & WHEEL_MASK];
} else {
/* in largest slot */
if (diff > LARGEST_SLOT) {
......
......@@ -219,7 +219,7 @@ class HHWheelTimer : protected folly::AsyncTimeout,
typedef Callback::List CallbackList;
CallbackList buckets_[WHEEL_BUCKETS][WHEEL_SIZE];
uint32_t timeToWheelTicks(std::chrono::milliseconds t) {
int64_t timeToWheelTicks(std::chrono::milliseconds t) {
return t.count() / interval_.count();
}
......
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