]>
git.proxmox.com Git - qemu.git/blob - event_notifier.c
2b210f4b44f4de254239c5010ca6f1217ee2a3ef
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 "event_notifier.h"
15 #include <sys/eventfd.h>
18 int event_notifier_init(EventNotifier
*e
, int active
)
21 int fd
= eventfd(!!active
, EFD_NONBLOCK
| EFD_CLOEXEC
);
31 void event_notifier_cleanup(EventNotifier
*e
)
36 int event_notifier_get_fd(EventNotifier
*e
)
41 int event_notifier_set(EventNotifier
*e
)
44 int r
= write(e
->fd
, &value
, sizeof(value
));
45 return r
== sizeof(value
);
48 int event_notifier_test_and_clear(EventNotifier
*e
)
51 int r
= read(e
->fd
, &value
, sizeof(value
));
52 return r
== sizeof(value
);
55 int event_notifier_test(EventNotifier
*e
)
58 int r
= read(e
->fd
, &value
, sizeof(value
));
59 if (r
== sizeof(value
)) {
60 /* restore previous value. */
61 int s
= write(e
->fd
, &value
, sizeof(value
));
62 /* never blocks because we use EFD_SEMAPHORE.
63 * If we didn't we'd get EAGAIN on overflow
64 * and we'd have to write code to ignore it. */
65 assert(s
== sizeof(value
));
67 return r
== sizeof(value
);