ivshmem: wrap ivshmem_del_eventfd loops with transaction
[qemu-kvm.git] / event_notifier.c
blob99c376c6a34b8ee6661772451df92bdb2187f072
1 /*
2 * event notifier support
4 * Copyright Red Hat, Inc. 2010
6 * Authors:
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"
16 #ifdef CONFIG_EVENTFD
17 #include <sys/eventfd.h>
18 #endif
20 void event_notifier_init_fd(EventNotifier *e, int fd)
22 e->fd = fd;
25 int event_notifier_init(EventNotifier *e, int active)
27 #ifdef CONFIG_EVENTFD
28 int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC);
29 if (fd < 0)
30 return -errno;
31 e->fd = fd;
32 return 0;
33 #else
34 return -ENOSYS;
35 #endif
38 void event_notifier_cleanup(EventNotifier *e)
40 close(e->fd);
43 int event_notifier_get_fd(EventNotifier *e)
45 return e->fd;
48 int event_notifier_set(EventNotifier *e)
50 uint64_t value = 1;
51 int r = write(e->fd, &value, sizeof(value));
52 return r == sizeof(value);
55 int event_notifier_test_and_clear(EventNotifier *e)
57 uint64_t value;
58 int r = read(e->fd, &value, sizeof(value));
59 return r == sizeof(value);