forked from mirror/ants
Merge branch 'master' into develop
This commit is contained in:
commit
e8b1147e29
7
pool.go
7
pool.go
|
@ -52,7 +52,10 @@ type Pool struct {
|
||||||
|
|
||||||
// lock for synchronous operation.
|
// lock for synchronous operation.
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
|
||||||
|
// cond for waiting idle worker
|
||||||
cond *sync.Cond
|
cond *sync.Cond
|
||||||
|
|
||||||
once sync.Once
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +199,10 @@ func (p *Pool) getWorker() *Worker {
|
||||||
}
|
}
|
||||||
|
|
||||||
if waiting {
|
if waiting {
|
||||||
for{
|
for {
|
||||||
p.cond.Wait()
|
p.cond.Wait()
|
||||||
l := len(p.workers) - 1
|
l := len(p.workers) - 1
|
||||||
if l < 0{
|
if l < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w = p.workers[l]
|
w = p.workers[l]
|
||||||
|
|
|
@ -50,7 +50,10 @@ type PoolWithFunc struct {
|
||||||
|
|
||||||
// lock for synchronous operation.
|
// lock for synchronous operation.
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
|
||||||
|
// cond for waiting idle worker
|
||||||
cond *sync.Cond
|
cond *sync.Cond
|
||||||
|
|
||||||
// pf is the function for processing tasks.
|
// pf is the function for processing tasks.
|
||||||
poolFunc pf
|
poolFunc pf
|
||||||
|
|
||||||
|
@ -198,10 +201,10 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
if waiting {
|
if waiting {
|
||||||
for{
|
for {
|
||||||
p.cond.Wait()
|
p.cond.Wait()
|
||||||
l := len(p.workers) - 1
|
l := len(p.workers) - 1
|
||||||
if l < 0{
|
if l < 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w = p.workers[l]
|
w = p.workers[l]
|
||||||
|
|
Loading…
Reference in New Issue