Merge branch 'develop'

This commit is contained in:
andy pan 2018-06-15 11:28:33 +08:00
commit d172d8355e
1 changed files with 9 additions and 15 deletions

View File

@ -122,7 +122,7 @@ func (p *PoolWithFunc) ReSize(size int) {
for i := 0; i < diff; i++ { for i := 0; i < diff; i++ {
p.getWorker().stop() p.getWorker().stop()
} }
} else if size == p.Cap(){ } else if size == p.Cap() {
return return
} }
atomic.StoreInt32(&p.capacity, int32(size)) atomic.StoreInt32(&p.capacity, int32(size))
@ -145,6 +145,7 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
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]
@ -153,20 +154,13 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
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 = &WorkerWithFunc{ w = &WorkerWithFunc{
pool: p, pool: p,