github.com/hauerwu/docker@v1.8.0-rc1/pkg/system/events_windows.go (about)

     1  package system
     2  
     3  // This file implements syscalls for Win32 events which are not implemented
     4  // in golang.
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  const (
    12  	EVENT_ALL_ACCESS    = 0x1F0003
    13  	EVENT_MODIFY_STATUS = 0x0002
    14  )
    15  
    16  var (
    17  	procCreateEvent = modkernel32.NewProc("CreateEventW")
    18  	procOpenEvent   = modkernel32.NewProc("OpenEventW")
    19  	procSetEvent    = modkernel32.NewProc("SetEvent")
    20  	procResetEvent  = modkernel32.NewProc("ResetEvent")
    21  	procPulseEvent  = modkernel32.NewProc("PulseEvent")
    22  )
    23  
    24  func CreateEvent(eventAttributes *syscall.SecurityAttributes, manualReset bool, initialState bool, name string) (handle syscall.Handle, err error) {
    25  	namep, _ := syscall.UTF16PtrFromString(name)
    26  	var _p1 uint32 = 0
    27  	if manualReset {
    28  		_p1 = 1
    29  	}
    30  	var _p2 uint32 = 0
    31  	if initialState {
    32  		_p2 = 1
    33  	}
    34  	r0, _, e1 := procCreateEvent.Call(uintptr(unsafe.Pointer(eventAttributes)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(namep)))
    35  	use(unsafe.Pointer(namep))
    36  	handle = syscall.Handle(r0)
    37  	if handle == syscall.InvalidHandle {
    38  		err = e1
    39  	}
    40  	return
    41  }
    42  
    43  func OpenEvent(desiredAccess uint32, inheritHandle bool, name string) (handle syscall.Handle, err error) {
    44  	namep, _ := syscall.UTF16PtrFromString(name)
    45  	var _p1 uint32 = 0
    46  	if inheritHandle {
    47  		_p1 = 1
    48  	}
    49  	r0, _, e1 := procOpenEvent.Call(uintptr(desiredAccess), uintptr(_p1), uintptr(unsafe.Pointer(namep)))
    50  	use(unsafe.Pointer(namep))
    51  	handle = syscall.Handle(r0)
    52  	if handle == syscall.InvalidHandle {
    53  		err = e1
    54  	}
    55  	return
    56  }
    57  
    58  func SetEvent(handle syscall.Handle) (err error) {
    59  	return setResetPulse(handle, procSetEvent)
    60  }
    61  
    62  func ResetEvent(handle syscall.Handle) (err error) {
    63  	return setResetPulse(handle, procResetEvent)
    64  }
    65  
    66  func PulseEvent(handle syscall.Handle) (err error) {
    67  	return setResetPulse(handle, procPulseEvent)
    68  }
    69  
    70  func setResetPulse(handle syscall.Handle, proc *syscall.LazyProc) (err error) {
    71  	r0, _, _ := proc.Call(uintptr(handle))
    72  	if r0 != 0 {
    73  		err = syscall.Errno(r0)
    74  	}
    75  	return
    76  }
    77  
    78  var temp unsafe.Pointer
    79  
    80  // use ensures a variable is kept alive without the GC freeing while still needed
    81  func use(p unsafe.Pointer) {
    82  	temp = p
    83  }