OSDN Git Service

select: adapt cancelation to use cancel.h
authorPeter S. Mazinger <ps.m@gmx.net>
Thu, 21 Apr 2011 19:55:48 +0000 (21:55 +0200)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 15 Jun 2012 12:00:40 +0000 (14:00 +0200)
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
include/sys/select.h
libc/sysdeps/linux/common/select.c

index 6ffe4e2..5436e20 100644 (file)
@@ -110,7 +110,10 @@ extern int select (int __nfds, fd_set *__restrict __readfds,
                   fd_set *__restrict __writefds,
                   fd_set *__restrict __exceptfds,
                   struct timeval *__restrict __timeout);
+#ifdef _LIBC
+extern __typeof(select) __select_nocancel attribute_hidden;
 libc_hidden_proto(select)
+#endif
 
 #ifdef __USE_XOPEN2K
 /* Same as above only that the TIMEOUT value is given with higher
index 029fb08..c13bd04 100644 (file)
@@ -9,27 +9,24 @@
 
 #include <sys/syscall.h>
 #include <sys/select.h>
-#include <stdint.h>
+#include <cancel.h>
 
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-#include <sysdep-cancel.h>
-#else
-#define SINGLE_THREAD_P 1
+#ifdef __NR__newselect
+# undef __NR_select
+# define __NR_select __NR__newselect
 #endif
 
-#define USEC_PER_SEC 1000000L
-
-extern __typeof(select) __libc_select;
-
-#if !defined(__NR__newselect) && !defined(__NR_select) && defined __USE_XOPEN2K
-# define __NR___libc_pselect6 __NR_pselect6
-static _syscall6(int, __libc_pselect6, int, n, fd_set *, readfds, fd_set *, writefds,
-        fd_set *, exceptfds, const struct timespec *, timeout,
-        const sigset_t *, sigmask)
+#if !defined __NR_select && defined __NR_pselect6
+# include <stdint.h>
+# define USEC_PER_SEC 1000000L
+#endif
 
-int __libc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
-                  struct timeval *timeout)
+int __NC(select)(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+                struct timeval *timeout)
 {
+#ifdef __NR_select
+       return INLINE_SYSCALL(select, 5, n, readfds, writefds, exceptfds, timeout);
+#elif defined __NR_pselect6
        struct timespec _ts, *ts = 0;
        if (timeout) {
                uint32_t usec;
@@ -51,44 +48,14 @@ int __libc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
 
                ts = &_ts;
        }
-
-       if (SINGLE_THREAD_P)
-               return __libc_pselect6(n, readfds, writefds, exceptfds, ts, 0);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-       int oldtype = LIBC_CANCEL_ASYNC ();
-       int result = __libc_pselect6(n, readfds, writefds, exceptfds, ts, 0);
-       LIBC_CANCEL_RESET (oldtype);
-       return result;
-#endif
-
-}
-
-#else
-
-#ifdef __NR__newselect
-# define __NR___syscall_select __NR__newselect
-#else
-# define __NR___syscall_select __NR_select
-#endif
-
-static _syscall5(int, __syscall_select, int, n, fd_set *, readfds,
-               fd_set *, writefds, fd_set *, exceptfds, struct timeval *, timeout);
-
-int __libc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
-                  struct timeval *timeout)
-{
-       if (SINGLE_THREAD_P)
-               return __syscall_select(n, readfds, writefds, exceptfds, timeout);
-
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-       int oldtype = LIBC_CANCEL_ASYNC ();
-       int result = __syscall_select(n, readfds, writefds, exceptfds, timeout);
-       LIBC_CANCEL_RESET (oldtype);
-       return result;
+       return INLINE_SYSCALL(pselect6, 6, n, readfds, writefds, exceptfds, ts, 0);
 #endif
 }
-
+/* we should guard it, but we need it in other files, so let it fail
+ * if we miss any of the syscalls */
+#if 1 /*defined __NR_select || defined __NR_pselect6*/
+CANCELLABLE_SYSCALL(int, select, (int n, fd_set *readfds, fd_set *writefds,
+                                 fd_set *exceptfds, struct timeval *timeout),
+                   (n, readfds, writefds, exceptfds, timeout))
+lt_libc_hidden(select)
 #endif
-
-weak_alias(__libc_select,select)
-libc_hidden_weak(select)