forked from mirror/ants
sync.Pool opt
This commit is contained in:
parent
5a77e7a59d
commit
3bfc4f2ebd
4
pool.go
4
pool.go
|
@ -115,13 +115,11 @@ func NewPool(size int, options ...Option) (*Pool, error) {
|
||||||
lock: internal.NewSpinLock(),
|
lock: internal.NewSpinLock(),
|
||||||
options: opts,
|
options: opts,
|
||||||
}
|
}
|
||||||
p.workerCache = sync.Pool{
|
p.workerCache.New = func() interface{} {
|
||||||
New: func() interface{} {
|
|
||||||
return &goWorker{
|
return &goWorker{
|
||||||
pool: p,
|
pool: p,
|
||||||
task: make(chan func(), workerChanCap),
|
task: make(chan func(), workerChanCap),
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
if p.options.PreAlloc {
|
if p.options.PreAlloc {
|
||||||
p.workers = newWorkerArray(loopQueueType, size)
|
p.workers = newWorkerArray(loopQueueType, size)
|
||||||
|
|
|
@ -137,13 +137,11 @@ func NewPoolWithFunc(size int, pf func(interface{}), options ...Option) (*PoolWi
|
||||||
lock: internal.NewSpinLock(),
|
lock: internal.NewSpinLock(),
|
||||||
options: opts,
|
options: opts,
|
||||||
}
|
}
|
||||||
p.workerCache = sync.Pool{
|
p.workerCache.New = func() interface{} {
|
||||||
New: func() interface{} {
|
|
||||||
return &goWorkerWithFunc{
|
return &goWorkerWithFunc{
|
||||||
pool: p,
|
pool: p,
|
||||||
args: make(chan interface{}, workerChanCap),
|
args: make(chan interface{}, workerChanCap),
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
if p.options.PreAlloc {
|
if p.options.PreAlloc {
|
||||||
p.workers = make([]*goWorkerWithFunc, 0, size)
|
p.workers = make([]*goWorkerWithFunc, 0, size)
|
||||||
|
|
Loading…
Reference in New Issue