go_dreamfactory/lego/sys/timewheel/task_pool.go
2022-06-07 20:18:22 +08:00

35 lines
410 B
Go

package timewheel
import (
"sync"
)
var incr = 0
var (
defaultTaskPool = newTaskPool()
)
type taskPool struct {
bp *sync.Pool
}
func newTaskPool() *taskPool {
return &taskPool{
bp: &sync.Pool{
New: func() interface{} {
return &Task{}
},
},
}
}
func (pool *taskPool) get() *Task {
return pool.bp.Get().(*Task)
}
func (pool *taskPool) put(obj *Task) {
obj.Reset()
pool.bp.Put(obj)
}