Keep the command DON'T DO COPIES!!!

This commit is contained in:
riccardom
2026-06-16 16:05:07 +02:00
parent 0503a18644
commit 8b76b3d824

View File

@@ -42,7 +42,7 @@ type runFunc func(ctx context.Context, mobileDep MobileDependency, runningChan c
// supervisor serializes start/stop of a single client run. Every request goes
// through cmdCh and is handled one at a time by the loop goroutine, so two
// lifecycle operations can never overlap and their order is preserved (FIFO).
// The loop goroutine is the sole owner of runCancel/runWaiter, so that state
// The loop goroutine is the sole owner of curExecOp/runCancel, so that state
// needs no locking. The loop exits when the parent context is cancelled.
type supervisor struct {
ctx context.Context
@@ -50,10 +50,11 @@ type supervisor struct {
cmdCh chan lifecycleCmd
runEnded chan runEndResult
// owned exclusively by the loop goroutine. A non-nil runCancel means a run
// is in flight; runWaiter is whoever asked to be notified when it ends.
// owned exclusively by the loop goroutine. curExecOp is the in-flight start
// command (nil = idle); its done channel is notified when the run ends.
// runCancel cancels that run.
curExecOp *lifecycleCmd
runCancel context.CancelFunc
runWaiter chan error
}
func newSupervisor(ctx context.Context, run runFunc) *supervisor {
@@ -88,14 +89,14 @@ func (s *supervisor) loop() {
}
func (s *supervisor) handleStart(cmd lifecycleCmd) {
if s.runCancel != nil {
if s.curExecOp != nil {
notify(cmd.done, errAlreadyRunning)
return
}
runCtx, cancel := context.WithCancel(s.ctx)
s.runCancel = cancel
s.runWaiter = cmd.done
s.curExecOp = &cmd
go func(ctx context.Context, m MobileDependency, rc chan struct{}, lp string) {
err := s.run(ctx, m, rc, lp)
@@ -104,7 +105,7 @@ func (s *supervisor) handleStart(cmd lifecycleCmd) {
}
func (s *supervisor) handleStop(cmd lifecycleCmd) {
if s.runCancel == nil {
if s.curExecOp == nil {
notify(cmd.done, nil)
return
}
@@ -122,9 +123,9 @@ func (s *supervisor) handleStop(cmd lifecycleCmd) {
// error back to whoever asked to be notified of the start.
func (s *supervisor) finishRun(err error) {
s.runCancel = nil
if s.runWaiter != nil {
notify(s.runWaiter, err)
s.runWaiter = nil
if s.curExecOp != nil {
notify(s.curExecOp.done, err)
s.curExecOp = nil
}
}