2 * event notifier support
4 * Copyright Red Hat, Inc. 2010
7 * Michael S. Tsirkin <mst@redhat.com>
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"
17 #include <sys/eventfd.h>
20 void event_notifier_init_fd(EventNotifier
*e
, int fd
)
25 int event_notifier_init(EventNotifier
*e
, int active
)
28 int fd
= eventfd(!!active
, EFD_NONBLOCK
| EFD_CLOEXEC
);
38 void event_notifier_cleanup(EventNotifier
*e
)
43 int event_notifier_get_fd(EventNotifier
*e
)
48 int event_notifier_set(EventNotifier
*e
)
51 int r
= write(e
->fd
, &value
, sizeof(value
));
52 return r
== sizeof(value
);
55 int event_notifier_test_and_clear(EventNotifier
*e
)
58 int r
= read(e
->fd
, &value
, sizeof(value
));
59 return r
== sizeof(value
);