optimization for getWorker()

This commit is contained in:
Andy Pan 2018-06-15 08:04:28 +08:00
parent affcb8eaf7
commit daf637e4f7
1 changed files with 8 additions and 14 deletions

22
pool.go
View File

@ -140,6 +140,7 @@ func (p *Pool) getWorker() *Worker {
p.running++
}
} else {
<-p.freeSignal
w = workers[n]
workers[n] = nil
p.workers = workers[:n]
@ -148,20 +149,13 @@ func (p *Pool) getWorker() *Worker {
if waiting {
<-p.freeSignal
for {
p.lock.Lock()
workers = p.workers
l := len(workers) - 1
if l < 0 {
p.lock.Unlock()
continue
}
w = workers[l]
workers[l] = nil
p.workers = workers[:l]
p.lock.Unlock()
break
}
p.lock.Lock()
workers = p.workers
l := len(workers) - 1
w = workers[l]
workers[l] = nil
p.workers = workers[:l]
p.lock.Unlock()
} else if w == nil {
w = &Worker{
pool: p,