]>
Commit | Line | Data |
---|---|---|
2292b339 MT |
1 | /* |
2 | * event notifier support | |
3 | * | |
4 | * Copyright Red Hat, Inc. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Michael S. Tsirkin <[email protected]> | |
8 | * | |
6b620ca3 PB |
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. | |
2292b339 MT |
11 | */ |
12 | ||
2292b339 MT |
13 | #include "event_notifier.h" |
14 | #ifdef CONFIG_EVENTFD | |
15 | #include <sys/eventfd.h> | |
16 | #endif | |
17 | ||
18 | int event_notifier_init(EventNotifier *e, int active) | |
19 | { | |
20 | #ifdef CONFIG_EVENTFD | |
21 | int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC); | |
22 | if (fd < 0) | |
23 | return -errno; | |
24 | e->fd = fd; | |
25 | return 0; | |
26 | #else | |
27 | return -ENOSYS; | |
28 | #endif | |
29 | } | |
30 | ||
31 | void event_notifier_cleanup(EventNotifier *e) | |
32 | { | |
33 | close(e->fd); | |
34 | } | |
35 | ||
36 | int event_notifier_get_fd(EventNotifier *e) | |
37 | { | |
38 | return e->fd; | |
39 | } | |
40 | ||
2ec10b95 PB |
41 | int event_notifier_set(EventNotifier *e) |
42 | { | |
43 | uint64_t value = 1; | |
44 | int r = write(e->fd, &value, sizeof(value)); | |
45 | return r == sizeof(value); | |
46 | } | |
47 | ||
2292b339 MT |
48 | int event_notifier_test_and_clear(EventNotifier *e) |
49 | { | |
50 | uint64_t value; | |
51 | int r = read(e->fd, &value, sizeof(value)); | |
52 | return r == sizeof(value); | |
53 | } |