Merge branch 'master' into develop

This commit is contained in:
AndyPan 2018-09-30 09:44:32 +08:00
commit e8b1147e29
2 changed files with 10 additions and 4 deletions

View File

@ -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]

View File

@ -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]