event_notifier-win32.c 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * event notifier support
  3. *
  4. * Copyright Red Hat, Inc. 2010
  5. *
  6. * Authors:
  7. * Michael S. Tsirkin <mst@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #include "qemu/osdep.h"
  13. #include "qemu/event_notifier.h"
  14. #include "qemu/main-loop.h"
  15. int event_notifier_init(EventNotifier *e, int active)
  16. {
  17. e->event = CreateEvent(NULL, TRUE, FALSE, NULL);
  18. assert(e->event);
  19. return 0;
  20. }
  21. void event_notifier_cleanup(EventNotifier *e)
  22. {
  23. CloseHandle(e->event);
  24. e->event = NULL;
  25. }
  26. HANDLE event_notifier_get_handle(EventNotifier *e)
  27. {
  28. return e->event;
  29. }
  30. int event_notifier_set(EventNotifier *e)
  31. {
  32. SetEvent(e->event);
  33. return 0;
  34. }
  35. int event_notifier_test_and_clear(EventNotifier *e)
  36. {
  37. int ret = WaitForSingleObject(e->event, 0);
  38. if (ret == WAIT_OBJECT_0) {
  39. ResetEvent(e->event);
  40. return true;
  41. }
  42. return false;
  43. }