From 3be57dc4a30f1a4b059fec4bd7e46ae03d3c7107 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 9 Jan 2013 23:01:04 +0100 Subject: fd_util: support eventfd() --- src/fd_util.c | 14 ++++++++++++++ src/fd_util.h | 11 +++++++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/fd_util.c b/src/fd_util.c index 882b4c7d5..ea29d6eaa 100644 --- a/src/fd_util.c +++ b/src/fd_util.c @@ -49,6 +49,10 @@ #include #endif +#ifdef HAVE_EVENTFD +#include +#endif + #ifndef WIN32 static int @@ -328,6 +332,16 @@ inotify_init_cloexec(void) #endif +#ifdef HAVE_EVENTFD + +int +eventfd_cloexec_nonblock(unsigned initval, int flags) +{ + return eventfd(initval, flags | EFD_CLOEXEC | EFD_NONBLOCK); +} + +#endif + int close_socket(int fd) { diff --git a/src/fd_util.h b/src/fd_util.h index c8a17c7ef..e65c6a69b 100644 --- a/src/fd_util.h +++ b/src/fd_util.h @@ -144,6 +144,17 @@ inotify_init_cloexec(void); #endif +#ifdef HAVE_EVENTFD + +/** + * Wrapper for eventfd() which sets the flags CLOEXEC and NONBLOCK + * flag (atomically if supported by the OS). + */ +int +eventfd_cloexec_nonblock(unsigned initval, int flags); + +#endif + /** * Portable wrapper for close(); use closesocket() on WIN32/WinSock. */ -- cgit v1.2.3