diff options
Diffstat (limited to 'libgo/go/os/exec_windows.go')
-rw-r--r-- | libgo/go/os/exec_windows.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/libgo/go/os/exec_windows.go b/libgo/go/os/exec_windows.go index 393393b2375..3264271b2e9 100644 --- a/libgo/go/os/exec_windows.go +++ b/libgo/go/os/exec_windows.go @@ -7,13 +7,15 @@ package os import ( "errors" "runtime" + "sync/atomic" "syscall" "time" "unsafe" ) func (p *Process) wait() (ps *ProcessState, err error) { - s, e := syscall.WaitForSingleObject(syscall.Handle(p.handle), syscall.INFINITE) + handle := atomic.LoadUintptr(&p.handle) + s, e := syscall.WaitForSingleObject(syscall.Handle(handle), syscall.INFINITE) switch s { case syscall.WAIT_OBJECT_0: break @@ -23,12 +25,12 @@ func (p *Process) wait() (ps *ProcessState, err error) { return nil, errors.New("os: unexpected result from WaitForSingleObject") } var ec uint32 - e = syscall.GetExitCodeProcess(syscall.Handle(p.handle), &ec) + e = syscall.GetExitCodeProcess(syscall.Handle(handle), &ec) if e != nil { return nil, NewSyscallError("GetExitCodeProcess", e) } var u syscall.Rusage - e = syscall.GetProcessTimes(syscall.Handle(p.handle), &u.CreationTime, &u.ExitTime, &u.KernelTime, &u.UserTime) + e = syscall.GetProcessTimes(syscall.Handle(handle), &u.CreationTime, &u.ExitTime, &u.KernelTime, &u.UserTime) if e != nil { return nil, NewSyscallError("GetProcessTimes", e) } @@ -53,7 +55,8 @@ func terminateProcess(pid, exitcode int) error { } func (p *Process) signal(sig Signal) error { - if p.handle == uintptr(syscall.InvalidHandle) { + handle := atomic.LoadUintptr(&p.handle) + if handle == uintptr(syscall.InvalidHandle) { return syscall.EINVAL } if p.done() { @@ -67,14 +70,15 @@ func (p *Process) signal(sig Signal) error { } func (p *Process) release() error { - if p.handle == uintptr(syscall.InvalidHandle) { + handle := atomic.LoadUintptr(&p.handle) + if handle == uintptr(syscall.InvalidHandle) { return syscall.EINVAL } - e := syscall.CloseHandle(syscall.Handle(p.handle)) + e := syscall.CloseHandle(syscall.Handle(handle)) if e != nil { return NewSyscallError("CloseHandle", e) } - p.handle = uintptr(syscall.InvalidHandle) + atomic.StoreUintptr(&p.handle, uintptr(syscall.InvalidHandle)) // no need for a finalizer anymore runtime.SetFinalizer(p, nil) return nil |