Revision 2292b339

b/Makefile.target
165 165
# virtio has to be here due to weird dependency between PCI and virtio-net.
166 166
# need to fix this properly
167 167
obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o
168
obj-y += event_notifier.o
168 169
obj-y += rwhandler.o
169 170
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
170 171
LIBS+=-lz
b/hw/event_notifier.c
1
/*
2
 * event notifier support
3
 *
4
 * Copyright Red Hat, Inc. 2010
5
 *
6
 * Authors:
7
 *  Michael S. Tsirkin <mst@redhat.com>
8
 *
9
 * This work is licensed under the terms of the GNU GPL, version 2.  See
10
 * the COPYING file in the top-level directory.
11
 */
12

  
13
#include "hw.h"
14
#include "event_notifier.h"
15
#ifdef CONFIG_EVENTFD
16
#include <sys/eventfd.h>
17
#endif
18

  
19
int event_notifier_init(EventNotifier *e, int active)
20
{
21
#ifdef CONFIG_EVENTFD
22
    int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC);
23
    if (fd < 0)
24
        return -errno;
25
    e->fd = fd;
26
    return 0;
27
#else
28
    return -ENOSYS;
29
#endif
30
}
31

  
32
void event_notifier_cleanup(EventNotifier *e)
33
{
34
    close(e->fd);
35
}
36

  
37
int event_notifier_get_fd(EventNotifier *e)
38
{
39
    return e->fd;
40
}
41

  
42
int event_notifier_test_and_clear(EventNotifier *e)
43
{
44
    uint64_t value;
45
    int r = read(e->fd, &value, sizeof(value));
46
    return r == sizeof(value);
47
}
48

  
49
int event_notifier_test(EventNotifier *e)
50
{
51
    uint64_t value;
52
    int r = read(e->fd, &value, sizeof(value));
53
    if (r == sizeof(value)) {
54
        /* restore previous value. */
55
        int s = write(e->fd, &value, sizeof(value));
56
        /* never blocks because we use EFD_SEMAPHORE.
57
         * If we didn't we'd get EAGAIN on overflow
58
         * and we'd have to write code to ignore it. */
59
        assert(s == sizeof(value));
60
    }
61
    return r == sizeof(value);
62
}
b/hw/event_notifier.h
1
#ifndef QEMU_EVENT_NOTIFIER_H
2
#define QEMU_EVENT_NOTIFIER_H
3

  
4
#include "qemu-common.h"
5

  
6
struct EventNotifier {
7
	int fd;
8
};
9

  
10
int event_notifier_init(EventNotifier *, int active);
11
void event_notifier_cleanup(EventNotifier *);
12
int event_notifier_get_fd(EventNotifier *);
13
int event_notifier_test_and_clear(EventNotifier *);
14
int event_notifier_test(EventNotifier *);
15

  
16
#endif
b/qemu-common.h
228 228
typedef struct I2SCodec I2SCodec;
229 229
typedef struct DeviceState DeviceState;
230 230
typedef struct SSIBus SSIBus;
231
typedef struct EventNotifier EventNotifier;
231 232

  
232 233
typedef uint64_t pcibus_t;
233 234

  

Also available in: Unified diff