Skip to content

Commit

Permalink
worker: decRunning when revertWorker is false
Browse files Browse the repository at this point in the history
Signed-off-by: Cholerae Hu <[email protected]>
  • Loading branch information
choleraehyq authored and panjf2000 committed Sep 12, 2019
1 parent 280ac34 commit d6cd5a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ func (w *goWorker) run() {
w.pool.incRunning()
go func() {
defer func() {
w.pool.decRunning()
if p := recover(); p != nil {
w.pool.decRunning()
w.pool.workerCache.Put(w)
if w.pool.panicHandler != nil {
w.pool.panicHandler(p)
} else {
Expand All @@ -60,17 +59,16 @@ func (w *goWorker) run() {
log.Printf("worker exits from panic: %s\n", string(buf[:n]))
}
}
w.pool.workerCache.Put(w)
}()

for f := range w.task {
if f == nil {
w.pool.decRunning()
w.pool.workerCache.Put(w)
return
}
f()
if ok := w.pool.revertWorker(w); !ok {
break
return
}
}
}()
Expand Down
8 changes: 3 additions & 5 deletions worker_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ func (w *goWorkerWithFunc) run() {
w.pool.incRunning()
go func() {
defer func() {
w.pool.decRunning()
if p := recover(); p != nil {
w.pool.decRunning()
w.pool.workerCache.Put(w)
if w.pool.panicHandler != nil {
w.pool.panicHandler(p)
} else {
Expand All @@ -60,17 +59,16 @@ func (w *goWorkerWithFunc) run() {
log.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
}
}
w.pool.workerCache.Put(w)
}()

for args := range w.args {
if args == nil {
w.pool.decRunning()
w.pool.workerCache.Put(w)
return
}
w.pool.poolFunc(args)
if ok := w.pool.revertWorker(w); !ok {
break
return
}
}
}()
Expand Down

0 comments on commit d6cd5a7

Please sign in to comment.