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 13 #include "qemu/osdep.h" 14 #include "qemu-common.h" 15 #include "qemu/event_notifier.h" 16 #include "qemu/main-loop.h" 17 18 int event_notifier_init(EventNotifier *e, int active) 19 { 20 e->event = CreateEvent(NULL, TRUE, FALSE, NULL); 21 assert(e->event); 22 e->cleanup = NULL; 23 return 0; 24 } 25 26 void event_notifier_cleanup(EventNotifier *e) 27 { 28 CloseHandle(e->event); 29 e->event = NULL; 30 e->cleanup = NULL; 31 } 32 33 HANDLE event_notifier_get_handle(EventNotifier *e) 34 { 35 return e->event; 36 } 37 38 int event_notifier_set(EventNotifier *e) 39 { 40 SetEvent(e->event); 41 return 0; 42 } 43 44 int event_notifier_test_and_clear(EventNotifier *e) 45 { 46 int ret = WaitForSingleObject(e->event, 0); 47 if (ret == WAIT_OBJECT_0) { 48 ResetEvent(e->event); 49 return true; 50 } 51 return false; 52 } 53