You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
979 B

  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package svc
  6. import (
  7. "errors"
  8. "golang.org/x/sys/windows"
  9. )
  10. // event represents auto-reset, initially non-signaled Windows event.
  11. // It is used to communicate between go and asm parts of this package.
  12. type event struct {
  13. h windows.Handle
  14. }
  15. func newEvent() (*event, error) {
  16. h, err := windows.CreateEvent(nil, 0, 0, nil)
  17. if err != nil {
  18. return nil, err
  19. }
  20. return &event{h: h}, nil
  21. }
  22. func (e *event) Close() error {
  23. return windows.CloseHandle(e.h)
  24. }
  25. func (e *event) Set() error {
  26. return windows.SetEvent(e.h)
  27. }
  28. func (e *event) Wait() error {
  29. s, err := windows.WaitForSingleObject(e.h, windows.INFINITE)
  30. switch s {
  31. case windows.WAIT_OBJECT_0:
  32. break
  33. case windows.WAIT_FAILED:
  34. return err
  35. default:
  36. return errors.New("unexpected result from WaitForSingleObject")
  37. }
  38. return nil
  39. }