From 773210897aff868320af09afb16aa6c7646559c8 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 16 Apr 2014 10:26:37 +0800 Subject: [PATCH] update --- timer/wheel.go | 13 +++++++------ timer/wheel_test.go | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/timer/wheel.go b/timer/wheel.go index 29ca387..644bd10 100644 --- a/timer/wheel.go +++ b/timer/wheel.go @@ -77,22 +77,23 @@ func NewWheel(tick time.Duration) *Wheel { } func (w *Wheel) addTimerInternal(t *timer) { + expires := t.expires idx := t.expires - w.jiffies var tv [][]*timer var i uint64 if idx < tvr_size { - i = t.expires & tvr_mask + i = expires & tvr_mask tv = w.tv1 } else if idx < (1 << (tvr_bits + tvn_bits)) { - i = (t.expires >> tvr_bits) & tvn_mask + i = (expires >> tvr_bits) & tvn_mask tv = w.tv2 } else if idx < (1 << (tvr_bits + 2*tvn_bits)) { - i = (t.expires >> (tvr_bits + tvn_bits)) & tvn_mask + i = (expires >> (tvr_bits + tvn_bits)) & tvn_mask tv = w.tv3 } else if idx < (1 << (tvr_bits + 3*tvn_bits)) { - i = (t.expires >> (tvr_bits + 2*tvn_bits)) & tvn_mask + i = (expires >> (tvr_bits + 2*tvn_bits)) & tvn_mask tv = w.tv4 } else if int64(idx) < 0 { i = w.jiffies & tvr_mask @@ -101,10 +102,10 @@ func (w *Wheel) addTimerInternal(t *timer) { if idx > 0x00000000ffffffff { idx = 0x00000000ffffffff - t.expires = idx + w.jiffies + expires = idx + w.jiffies } - i = (t.expires >> (tvr_bits + 3*tvn_bits)) & tvn_mask + i = (expires >> (tvr_bits + 3*tvn_bits)) & tvn_mask tv = w.tv5 } diff --git a/timer/wheel_test.go b/timer/wheel_test.go index d8bf13d..07c31d0 100644 --- a/timer/wheel_test.go +++ b/timer/wheel_test.go @@ -5,7 +5,7 @@ import ( "time" ) -var testWheel = NewWheel(100 * time.Millisecond) +var testWheel = NewWheel(1 * time.Millisecond) func TestTimer(t *testing.T) { t1 := testWheel.NewTimer(500 * time.Millisecond) @@ -39,5 +39,4 @@ func TestTicker(t *testing.T) { after := time.Now() println(after.Sub(before).String()) - }