diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2010-02-11 00:23:46 +0100 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-02-17 14:59:00 +0200 |
commit | f3dfda6114fd12ca7caac456b1997962b5c48274 (patch) | |
tree | 0768d67a8b17a09fa27ad4cfa5fdfc438981393a /osdep.c | |
parent | bf76bafa5ade434ef2747ceeeeaa95510ecb7946 (diff) |
use eventfd for iothread
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'osdep.c')
-rw-r--r-- | osdep.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -37,6 +37,10 @@ #include <sys/statvfs.h> #endif +#ifdef CONFIG_EVENTFD +#include <sys/eventfd.h> +#endif + #ifdef _WIN32 #include <windows.h> #elif defined(CONFIG_BSD) @@ -281,6 +285,34 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) #ifndef _WIN32 /* + * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set. + */ +int qemu_eventfd(int fds[2]) +{ + int ret; + +#ifdef CONFIG_EVENTFD + ret = eventfd(0, 0); + if (ret >= 0) { + fds[0] = ret; + qemu_set_cloexec(ret); + if ((fds[1] = dup(ret)) == -1) { + close(ret); + return -1; + } + qemu_set_cloexec(fds[1]); + return 0; + } + + if (errno != ENOSYS) { + return -1; + } +#endif + + return qemu_pipe(fds); +} + +/* * Creates a pipe with FD_CLOEXEC set on both file descriptors */ int qemu_pipe(int pipefd[2]) |