sync.Pool opt

This commit is contained in:
Andy Pan 2019-10-24 22:32:12 +08:00
parent 5a77e7a59d
commit 3bfc4f2ebd
2 changed files with 10 additions and 14 deletions

12
pool.go
View File

@ -115,13 +115,11 @@ func NewPool(size int, options ...Option) (*Pool, error) {
lock: internal.NewSpinLock(),
options: opts,
}
p.workerCache = sync.Pool{
New: func() interface{} {
return &goWorker{
pool: p,
task: make(chan func(), workerChanCap),
}
},
p.workerCache.New = func() interface{} {
return &goWorker{
pool: p,
task: make(chan func(), workerChanCap),
}
}
if p.options.PreAlloc {
p.workers = newWorkerArray(loopQueueType, size)

View File

@ -137,13 +137,11 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi
lock: internal.NewSpinLock(),
options: opts,
}
p.workerCache = sync.Pool{
New: func() interface{} {
return &goWorkerWithFunc{
pool: p,
args: make(chan interface{}, workerChanCap),
}
},
p.workerCache.New = func() interface{} {
return &goWorkerWithFunc{
pool: p,
args: make(chan interface{}, workerChanCap),
}
}
if p.options.PreAlloc {
p.workers = make([]*goWorkerWithFunc, 0, size)