blob: 9352da4699c736f1f6709b8e0e7d723268dc3cbe [file] [log] [blame]
Paolo Bonzinifc97a652010-05-24 17:26:13 +02001/*
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
Peter Maydellaafd7582016-01-29 17:49:55 +000013#include "qemu/osdep.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010014#include "qemu/event_notifier.h"
15#include "qemu/main-loop.h"
Paolo Bonzinifc97a652010-05-24 17:26:13 +020016
17int event_notifier_init(EventNotifier *e, int active)
18{
Jan Kiszkae9bff102012-11-22 20:56:11 +010019 e->event = CreateEvent(NULL, TRUE, FALSE, NULL);
Paolo Bonzinifc97a652010-05-24 17:26:13 +020020 assert(e->event);
21 return 0;
22}
23
24void event_notifier_cleanup(EventNotifier *e)
25{
26 CloseHandle(e->event);
Halil Pasicaa262922017-03-02 19:13:08 +010027 e->event = NULL;
Paolo Bonzinifc97a652010-05-24 17:26:13 +020028}
29
30HANDLE event_notifier_get_handle(EventNotifier *e)
31{
32 return e->event;
33}
34
Paolo Bonzinifc97a652010-05-24 17:26:13 +020035int event_notifier_set(EventNotifier *e)
36{
37 SetEvent(e->event);
38 return 0;
39}
40
41int event_notifier_test_and_clear(EventNotifier *e)
42{
43 int ret = WaitForSingleObject(e->event, 0);
44 if (ret == WAIT_OBJECT_0) {
45 ResetEvent(e->event);
46 return true;
47 }
48 return false;
49}