[vlc-commits] input: add vlc_poll_i11e() support for Linux event file descriptor

Rémi Denis-Courmont git at videolan.org
Wed Jul 1 18:22:11 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jun 30 23:52:51 2015 +0300| [a759610825764a1b2c4a11c2364b6e2605dc453f] | committer: Rémi Denis-Courmont

input: add vlc_poll_i11e() support for Linux event file descriptor

This saves one file descriptor and some kernel resources.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a759610825764a1b2c4a11c2364b6e2605dc453f
---

 src/misc/interrupt.c |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/misc/interrupt.c b/src/misc/interrupt.c
index c2a87d7..cefcf9c 100644
--- a/src/misc/interrupt.c
+++ b/src/misc/interrupt.c
@@ -32,6 +32,9 @@
 #ifdef HAVE_POLL
 #include <poll.h>
 #endif
+#ifdef HAVE_SYS_EVENTFD_H
+# include <sys/eventfd.h>
+#endif
 
 #include <vlc_common.h>
 #include <vlc_fs.h> /* vlc_pipe */
@@ -256,7 +259,8 @@ static void vlc_poll_i11e_cleanup(void *opaque)
     int *fd = ctx->data;
 
     vlc_interrupt_finish(ctx);
-    close(fd[1]);
+    if (fd[1] != fd[0])
+        close(fd[1]);
     close(fd[0]);
 }
 
@@ -269,7 +273,14 @@ static int vlc_poll_i11e_inner(struct pollfd *restrict fds, unsigned nfds,
     int canc;
 
     /* TODO: cache this */
-    /* TODO: use eventfd on Linux */
+# if defined (HAVE_SYS_EVENTFD_H) && defined (EFD_CLOEXEC)
+    canc = vlc_savecancel();
+    fd[0] = eventfd(0, EFD_CLOEXEC);
+    vlc_restorecancel(canc);
+    if (fd[0] != -1)
+        fd[1] = fd[0];
+    else
+# endif
     if (vlc_pipe(fd))
     {
         vlc_testcancel();
@@ -314,7 +325,8 @@ static int vlc_poll_i11e_inner(struct pollfd *restrict fds, unsigned nfds,
     }
 out:
     canc = vlc_savecancel();
-    close(fd[1]);
+    if (fd[1] != fd[0])
+        close(fd[1]);
     close(fd[0]);
     vlc_restorecancel(canc);
     return ret;



More information about the vlc-commits mailing list