// This is a pointer to a separate memory allocation
// so that we can use runtime.AddCleanup.
handle *processHandle
+
+ // cleanup is used to clean up the process handle.
+ cleanup runtime.Cleanup
}
// processHandle holds an operating system handle to a process.
p := &Process{
Pid: pid,
}
- runtime.SetFinalizer(p, (*Process).Release)
return p
}
Pid: pid,
handle: ph,
}
- runtime.SetFinalizer(p, (*Process).Release)
+
+ p.cleanup = runtime.AddCleanup(p, (*processHandle).release, ph)
+
return p
}
Pid: pid,
}
p.state.Store(uint32(statusDone)) // No persistent reference, as there is no handle.
- runtime.SetFinalizer(p, (*Process).Release)
return p
}
if !p.state.CompareAndSwap(state, uint32(reason)) {
continue
}
+
+ // No need for more cleanup.
+ p.cleanup.Stop()
+
p.handle.release()
+
return status
}
}
import (
"internal/itoa"
- "runtime"
"syscall"
"time"
)
// Just mark the PID unusable.
p.pidDeactivate(statusReleased)
- // no need for a finalizer anymore
- runtime.SetFinalizer(p, nil)
return nil
}
import (
"errors"
- "runtime"
"syscall"
"time"
)
// Just mark the PID unusable.
p.pidDeactivate(statusReleased)
}
- // no need for a finalizer anymore
- runtime.SetFinalizer(p, nil)
+
return nil
}