From b01aec06b4d947c549508117a529782ad231f613 Mon Sep 17 00:00:00 2001 From: Haijun Zhu Date: Mon, 29 Sep 2014 10:09:38 -0700 Subject: [PATCH] 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 --- folly/io/async/HHWheelTimer.cpp | 8 ++++---- folly/io/async/HHWheelTimer.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/folly/io/async/HHWheelTimer.cpp b/folly/io/async/HHWheelTimer.cpp index 81275d61..587a2710 100644 --- a/folly/io/async/HHWheelTimer.cpp +++ b/folly/io/async/HHWheelTimer.cpp @@ -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) { diff --git a/folly/io/async/HHWheelTimer.h b/folly/io/async/HHWheelTimer.h index 36a7d0f2..b55d8857 100644 --- a/folly/io/async/HHWheelTimer.h +++ b/folly/io/async/HHWheelTimer.h @@ -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(); } -- 2.34.1