File tree 1 file changed +26
-9
lines changed 1 file changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -381,20 +381,37 @@ func (p *WorkerPool) pause() {
381
381
382
382
// Resume resumes the WorkerPool
383
383
func (p * WorkerPool ) Resume () {
384
- p .lock .Lock ()
384
+ p .lock .Lock () // can't defer unlock because of the zeroBoost at the end
385
385
select {
386
386
case <- p .resumed :
387
+ // already resumed - there's nothing to do
387
388
p .lock .Unlock ()
389
+ return
388
390
default :
389
- p .paused = make (chan struct {})
390
- close (p .resumed )
391
- if ! p .hasNoWorkerScaling () && p .numberOfWorkers == 0 && atomic .LoadInt64 (& p .numInQueue ) > 0 {
392
- p .zeroBoost ()
393
- // p.zeroBoost will unlock the lock
394
- } else {
395
- p .lock .Unlock ()
396
- }
397
391
}
392
+
393
+ p .paused = make (chan struct {})
394
+ close (p .resumed )
395
+
396
+ // OK now we need to check if we need to add some workers...
397
+ if p .numberOfWorkers > 0 || p .hasNoWorkerScaling () || atomic .LoadInt64 (& p .numInQueue ) == 0 {
398
+ // We either have workers, can't scale or there's no work to be done -> so just resume
399
+ p .lock .Unlock ()
400
+ return
401
+ }
402
+
403
+ // OK we got some work but no workers we need to think about boosting
404
+ select {
405
+ case <- p .baseCtx .Done ():
406
+ // don't bother boosting if the baseCtx is done
407
+ p .lock .Unlock ()
408
+ return
409
+ default :
410
+ }
411
+
412
+ // OK we'd better add some boost workers!
413
+ p .zeroBoost ()
414
+ // p.zeroBoost will unlock the lock
398
415
}
399
416
400
417
// CleanUp will drain the remaining contents of the channel
You can’t perform that action at this time.
0 commit comments