2 * event notifier support
4 * Copyright Red Hat, Inc. 2010
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.
13 #include "qemu-common.h"
14 #include "event_notifier.h"
15 #include "qemu-char.h"
18 #include <sys/eventfd.h>
21 void event_notifier_init_fd(EventNotifier *e, int fd)
26 int event_notifier_init(EventNotifier *e, int active)
29 int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC);
39 void event_notifier_cleanup(EventNotifier *e)
44 int event_notifier_get_fd(EventNotifier *e)
49 int event_notifier_set_handler(EventNotifier *e,
50 EventNotifierHandler *handler)
52 return qemu_set_fd_handler(e->fd, (IOHandler *)handler, NULL, e);
55 int event_notifier_set(EventNotifier *e)
58 int r = write(e->fd, &value, sizeof(value));
59 return r == sizeof(value);
62 int event_notifier_test_and_clear(EventNotifier *e)
65 int r = read(e->fd, &value, sizeof(value));
66 return r == sizeof(value);