aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-09 23:01:04 +0100
committerMax Kellermann <max@duempel.org>2013-01-10 00:10:01 +0100
commit3be57dc4a30f1a4b059fec4bd7e46ae03d3c7107 (patch)
tree88a1164b99c7653eb6de26c314c4cf3778921c8a
parenta93caf3cfe461ab7a19b86f456da576e4720fb7b (diff)
downloadmpd-3be57dc4a30f1a4b059fec4bd7e46ae03d3c7107.tar.gz
mpd-3be57dc4a30f1a4b059fec4bd7e46ae03d3c7107.tar.xz
mpd-3be57dc4a30f1a4b059fec4bd7e46ae03d3c7107.zip
fd_util: support eventfd()
-rw-r--r--configure.ac2
-rw-r--r--src/fd_util.c14
-rw-r--r--src/fd_util.h11
3 files changed, 26 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 9ade4bdf2..cdc236048 100644
--- a/configure.ac
+++ b/configure.ac
@@ -133,7 +133,7 @@ AC_SEARCH_LIBS([syslog], [bsd socket inet],
AC_SEARCH_LIBS([socket], [socket])
AC_SEARCH_LIBS([gethostbyname], [nsl])
-AC_CHECK_FUNCS(pipe2 accept4)
+AC_CHECK_FUNCS(pipe2 accept4 eventfd)
AC_SEARCH_LIBS([exp], [m],,
[AC_MSG_ERROR([exp() not found])])
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 <sys/inotify.h>
#endif
+#ifdef HAVE_EVENTFD
+#include <sys/eventfd.h>
+#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.
*/