From e009b5fbd81bd1d941ef6fb802ebeab334f4507f Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 3 Apr 2014 17:14:47 +0800 Subject: [PATCH] timingwheel remove task pool --- timingwheel/timingwheel.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/timingwheel/timingwheel.go b/timingwheel/timingwheel.go index 210d8fa..a27d334 100644 --- a/timingwheel/timingwheel.go +++ b/timingwheel/timingwheel.go @@ -14,7 +14,6 @@ type bucket struct { } const defaultTasksSize = 16 -const defaultTaskPool = 4 type TimingWheel struct { sync.Mutex @@ -29,8 +28,6 @@ type TimingWheel struct { buckets []bucket pos int - - tasks chan []TaskFunc } func NewTimingWheel(interval time.Duration, buckets int) *TimingWheel { @@ -53,12 +50,6 @@ func NewTimingWheel(interval time.Duration, buckets int) *TimingWheel { w.ticker = time.NewTicker(interval) go w.run() - w.tasks = make(chan []TaskFunc, 1024) - - for i := 0; i < defaultTaskPool; i++ { - go w.taskPool() - } - return w } @@ -123,24 +114,18 @@ func (w *TimingWheel) onTicker() { close(lastC) - w.tasks <- tasks -} - -func (w *TimingWheel) taskPool() { - defer func() { - if e := recover(); e != nil { - log.Fatal("task pool fatal %v", e) - } - }() - - for { - select { - case tasks := <-w.tasks: + if len(tasks) > 0 { + f := func(tasks []TaskFunc) { + defer func() { + if e := recover(); e != nil { + log.Fatal("run task fatal %v", e) + } + }() for _, task := range tasks { task() } - case <-w.quit: - return } + + go f(tasks) } }