mirror of https://github.com/panjf2000/ants.git
optimization for getWorker()
This commit is contained in:
parent
affcb8eaf7
commit
daf637e4f7
22
pool.go
22
pool.go
|
@ -140,6 +140,7 @@ func (p *Pool) getWorker() *Worker {
|
||||||
p.running++
|
p.running++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
<-p.freeSignal
|
||||||
w = workers[n]
|
w = workers[n]
|
||||||
workers[n] = nil
|
workers[n] = nil
|
||||||
p.workers = workers[:n]
|
p.workers = workers[:n]
|
||||||
|
@ -148,20 +149,13 @@ func (p *Pool) getWorker() *Worker {
|
||||||
|
|
||||||
if waiting {
|
if waiting {
|
||||||
<-p.freeSignal
|
<-p.freeSignal
|
||||||
for {
|
p.lock.Lock()
|
||||||
p.lock.Lock()
|
workers = p.workers
|
||||||
workers = p.workers
|
l := len(workers) - 1
|
||||||
l := len(workers) - 1
|
w = workers[l]
|
||||||
if l < 0 {
|
workers[l] = nil
|
||||||
p.lock.Unlock()
|
p.workers = workers[:l]
|
||||||
continue
|
p.lock.Unlock()
|
||||||
}
|
|
||||||
w = workers[l]
|
|
||||||
workers[l] = nil
|
|
||||||
p.workers = workers[:l]
|
|
||||||
p.lock.Unlock()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else if w == nil {
|
} else if w == nil {
|
||||||
w = &Worker{
|
w = &Worker{
|
||||||
pool: p,
|
pool: p,
|
||||||
|
|
Loading…
Reference in New Issue