]> Cypherpunks repositories - gostls13.git/commitdiff
os: use atomic.Uintptr for Process.handle
authorKir Kolyshkin <kolyshkin@gmail.com>
Thu, 23 Nov 2023 19:43:56 +0000 (11:43 -0800)
committerMichael Pratt <mpratt@google.com>
Wed, 21 Feb 2024 21:23:31 +0000 (21:23 +0000)
Suggested-by: Michael Knyszek <mknyszek@google.com>
Change-Id: I116731b6c3738aae8ff1d3be227f8f51fa3320c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/544795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: qiulaidongfeng <2645477756@qq.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/exec.go
src/os/exec_windows.go

index ed5a75c4d13f87405dde7c123896d5a4bf03784a..42e8a399a9878c15cfa6e5f38bf21ede6a7d7c1f 100644 (file)
@@ -20,13 +20,14 @@ var ErrProcessDone = errors.New("os: process already finished")
 // Process stores the information about a process created by StartProcess.
 type Process struct {
        Pid    int
-       handle uintptr      // handle is accessed atomically on Windows
+       handle atomic.Uintptr
        isdone atomic.Bool  // process has been successfully waited on
        sigMu  sync.RWMutex // avoid race between wait and signal
 }
 
 func newProcess(pid int, handle uintptr) *Process {
-       p := &Process{Pid: pid, handle: handle}
+       p := &Process{Pid: pid}
+       p.handle.Store(handle)
        runtime.SetFinalizer(p, (*Process).Release)
        return p
 }
index 061a12b10f3d9f014bb0f05d0bba90a1ac27735d..9aa5b147c939d73943c69433a54e35fc354fa97f 100644 (file)
@@ -8,13 +8,12 @@ import (
        "errors"
        "internal/syscall/windows"
        "runtime"
-       "sync/atomic"
        "syscall"
        "time"
 )
 
 func (p *Process) wait() (ps *ProcessState, err error) {
-       handle := atomic.LoadUintptr(&p.handle)
+       handle := p.handle.Load()
        s, e := syscall.WaitForSingleObject(syscall.Handle(handle), syscall.INFINITE)
        switch s {
        case syscall.WAIT_OBJECT_0:
@@ -40,7 +39,7 @@ func (p *Process) wait() (ps *ProcessState, err error) {
 }
 
 func (p *Process) signal(sig Signal) error {
-       handle := atomic.LoadUintptr(&p.handle)
+       handle := p.handle.Load()
        if handle == uintptr(syscall.InvalidHandle) {
                return syscall.EINVAL
        }
@@ -63,7 +62,7 @@ func (p *Process) signal(sig Signal) error {
 }
 
 func (p *Process) release() error {
-       handle := atomic.SwapUintptr(&p.handle, uintptr(syscall.InvalidHandle))
+       handle := p.handle.Swap(uintptr(syscall.InvalidHandle))
        if handle == uintptr(syscall.InvalidHandle) {
                return syscall.EINVAL
        }