Fix bug and unit test failure in HHWheelTimer
authorHaijun Zhu <haijunz@fb.com>
Mon, 29 Sep 2014 17:09:38 +0000 (10:09 -0700)
committerDave Watson <davejwatson@fb.com>
Tue, 30 Sep 2014 23:16:22 +0000 (16:16 -0700)
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
folly/io/async/HHWheelTimer.h

index 81275d61a7f5a7c0fee6289a59f8d6f5ad3a4189..587a271003c09a6d90d6adb93596583dea3b2ded 100644 (file)
@@ -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) {
index 36a7d0f2a5badcd6451bb7ed17f17cdf77387c2e..b55d88578b0dc28cfd88d819d55d5b1b1c0540d1 100644 (file)
@@ -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();
   }