Commit 980327fe authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Alex Brainman

windows: Implement WaitForMultipleObjects

This is a very classic and highly useful Windows API that I'm surprised
it's still not here.

Change-Id: If54319099cd94dd727126c579dd5a681979321cd
Reviewed-on: https://go-review.googlesource.com/c/160937
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
parent 7ae0202e
...@@ -172,6 +172,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { ...@@ -172,6 +172,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
//sys GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) //sys GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error)
//sys DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) //sys DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error)
//sys WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff] //sys WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff]
//sys waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff] = WaitForMultipleObjects
//sys GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) = GetTempPathW //sys GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) = GetTempPathW
//sys CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) //sys CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error)
//sys GetFileType(filehandle Handle) (n uint32, err error) //sys GetFileType(filehandle Handle) (n uint32, err error)
...@@ -589,6 +590,18 @@ func LoadSetFileCompletionNotificationModes() error { ...@@ -589,6 +590,18 @@ func LoadSetFileCompletionNotificationModes() error {
return procSetFileCompletionNotificationModes.Find() return procSetFileCompletionNotificationModes.Find()
} }
func WaitForMultipleObjects(handles []Handle, waitAll bool, waitMilliseconds uint32) (event uint32, err error) {
// Every other win32 array API takes arguments as "pointer, count", except for this function. So we
// can't declare it as a usual [] type, because mksyscall will use the opposite order. We therefore
// trivially stub this ourselves.
var handlePtr *Handle
if len(handles) > 0 {
handlePtr = &handles[0]
}
return waitForMultipleObjects(uint32(len(handles)), uintptr(unsafe.Pointer(handlePtr)), waitAll, waitMilliseconds)
}
// net api calls // net api calls
const socket_error = uintptr(^uint32(0)) const socket_error = uintptr(^uint32(0))
......
...@@ -112,6 +112,7 @@ var ( ...@@ -112,6 +112,7 @@ var (
procGetProcessTimes = modkernel32.NewProc("GetProcessTimes") procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
procDuplicateHandle = modkernel32.NewProc("DuplicateHandle") procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject") procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
procWaitForMultipleObjects = modkernel32.NewProc("WaitForMultipleObjects")
procGetTempPathW = modkernel32.NewProc("GetTempPathW") procGetTempPathW = modkernel32.NewProc("GetTempPathW")
procCreatePipe = modkernel32.NewProc("CreatePipe") procCreatePipe = modkernel32.NewProc("CreatePipe")
procGetFileType = modkernel32.NewProc("GetFileType") procGetFileType = modkernel32.NewProc("GetFileType")
...@@ -1084,6 +1085,25 @@ func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, ...@@ -1084,6 +1085,25 @@ func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32,
return return
} }
func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) {
var _p0 uint32
if waitAll {
_p0 = 1
} else {
_p0 = 0
}
r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0)
event = uint32(r0)
if event == 0xffffffff {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) { func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0) r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
n = uint32(r0) n = uint32(r0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment