Refactor WorkerCtx to use a boolean for isStopWorker
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/safing/portmaster/base/log"
|
"github.com/safing/portmaster/base/log"
|
||||||
@@ -36,7 +35,7 @@ type WorkerCtx struct {
|
|||||||
// the manager. When true, the manager will not wait for this worker to
|
// the manager. When true, the manager will not wait for this worker to
|
||||||
// finish during stop, preventing deadlocks where the stop worker
|
// finish during stop, preventing deadlocks where the stop worker
|
||||||
// would wait for itself to complete.
|
// would wait for itself to complete.
|
||||||
isStopWorker atomic.Bool
|
isStopWorker bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddToCtx adds the WorkerCtx to the given context.
|
// AddToCtx adds the WorkerCtx to the given context.
|
||||||
@@ -273,12 +272,12 @@ func (m *Manager) DoAsStopWorker(name string, fn func(w *WorkerCtx) error) error
|
|||||||
func (m *Manager) do(name string, isStopWorker bool, fn func(w *WorkerCtx) error) error {
|
func (m *Manager) do(name string, isStopWorker bool, fn func(w *WorkerCtx) error) error {
|
||||||
// Create context.
|
// Create context.
|
||||||
w := &WorkerCtx{
|
w := &WorkerCtx{
|
||||||
name: name,
|
name: name,
|
||||||
workFunc: fn,
|
workFunc: fn,
|
||||||
ctx: m.Ctx(),
|
ctx: m.Ctx(),
|
||||||
logger: m.logger.With("worker", name),
|
logger: m.logger.With("worker", name),
|
||||||
|
isStopWorker: isStopWorker,
|
||||||
}
|
}
|
||||||
w.isStopWorker.Store(isStopWorker)
|
|
||||||
|
|
||||||
m.workerStart(w)
|
m.workerStart(w)
|
||||||
defer m.workerDone(w)
|
defer m.workerDone(w)
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (m *Manager) hasStopWorker() bool {
|
|||||||
if w == nil {
|
if w == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if w.isStopWorker.Load() {
|
if w.isStopWorker {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user