From 145ad1d976abff15f32e129e25f47c04807d24ac Mon Sep 17 00:00:00 2001 From: "Peter S. Mazinger" Date: Fri, 22 Apr 2011 00:42:58 +0200 Subject: poll, ppoll: use cancel.h use __SYSCALL_SIGSET_T_SIZE use non-cancellable select in fallback Signed-off-by: Peter S. Mazinger Signed-off-by: Bernhard Reutner-Fischer --- libc/sysdeps/linux/common/poll.c | 36 +++++++++++------------------------- libc/sysdeps/linux/common/ppoll.c | 38 ++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 47 deletions(-) (limited to 'libc/sysdeps') diff --git a/libc/sysdeps/linux/common/poll.c b/libc/sysdeps/linux/common/poll.c index 92c90da66..891d2fba4 100644 --- a/libc/sysdeps/linux/common/poll.c +++ b/libc/sysdeps/linux/common/poll.c @@ -20,31 +20,14 @@ #include #include #include - -#ifdef __UCLIBC_HAS_THREADS_NATIVE__ -#include -#else -#define SINGLE_THREAD_P 1 -#endif +#include #if defined __ASSUME_POLL_SYSCALL && defined __NR_poll -#define __NR___syscall_poll __NR_poll -static _syscall3(int, __syscall_poll, struct pollfd *, fds, - unsigned long int, nfds, int, timeout); +#define __NR___poll_nocancel __NR_poll +static _syscall3(int, __NC(poll), struct pollfd *, fds, + unsigned long int, nfds, int, timeout) -int poll(struct pollfd *fds, nfds_t nfds, int timeout) -{ - if (SINGLE_THREAD_P) - return __syscall_poll(fds, nfds, timeout); - -#ifdef __UCLIBC_HAS_THREADS_NATIVE__ - int oldtype = LIBC_CANCEL_ASYNC (); - int result = __syscall_poll(fds, nfds, timeout); - LIBC_CANCEL_RESET (oldtype); - return result; -#endif -} #else /* !__NR_poll */ #include @@ -54,6 +37,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) #include #include #include +#include /* uClinux 2.0 doesn't have poll, emulate it using select */ @@ -63,7 +47,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) Returns the number of file descriptors with events, zero if timed out, or -1 for errors. */ -int poll(struct pollfd *fds, nfds_t nfds, int timeout) +int __NC(poll)(struct pollfd *fds, nfds_t nfds, int timeout) { static int max_fd_size; struct timeval tv; @@ -134,7 +118,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) while (1) { - ready = select (maxfd + 1, rset, wset, xset, + ready = __NC(select) (maxfd + 1, rset, wset, xset, timeout == -1 ? NULL : &tv); /* It might be that one or more of the file descriptors is invalid. @@ -177,7 +161,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) if (f->events & POLLPRI) FD_SET (f->fd, sngl_xset); - n = select (f->fd + 1, sngl_rset, sngl_wset, sngl_xset, + n = __NC(select) (f->fd + 1, sngl_rset, sngl_wset, sngl_xset, &sngl_tv); if (n != -1) { @@ -222,4 +206,6 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) } #endif -libc_hidden_def(poll) +CANCELLABLE_SYSCALL(int, poll, (struct pollfd *fds, nfds_t nfds, int timeout), + (fds, nfds, timeout)) +lt_libc_hidden(poll) diff --git a/libc/sysdeps/linux/common/ppoll.c b/libc/sysdeps/linux/common/ppoll.c index 3ca3f7333..9135fe523 100644 --- a/libc/sysdeps/linux/common/ppoll.c +++ b/libc/sysdeps/linux/common/ppoll.c @@ -20,19 +20,16 @@ #include #if defined __NR_ppoll && defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU -# define __need_NULL -# include -# include -# include -# ifdef __UCLIBC_HAS_THREADS_NATIVE__ -# include -# else -# define SINGLE_THREAD_P 1 -# endif - -int -ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, - const sigset_t *sigmask) + +#define __need_NULL +#include +#include +#include +#include + +static int +__NC(ppoll)(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, + const sigset_t *sigmask) { /* The Linux kernel can in some situations update the timeout value. We do not want that so use a local variable. */ @@ -41,14 +38,11 @@ ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, tval = *timeout; timeout = &tval; } - if (SINGLE_THREAD_P) - return INLINE_SYSCALL(ppoll, 5, fds, nfds, timeout, sigmask, _NSIG / 8); - -# ifdef __UCLIBC_HAS_THREADS_NATIVE__ - int oldtype = LIBC_CANCEL_ASYNC (); - int result = INLINE_SYSCALL(ppoll, 5, fds, nfds, timeout, sigmask, _NSIG / 8); - LIBC_CANCEL_RESET (oldtype); - return result; -# endif + return INLINE_SYSCALL(ppoll, 5, fds, nfds, timeout, sigmask, __SYSCALL_SIGSET_T_SIZE); } + +CANCELLABLE_SYSCALL(int, ppoll, (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, + const sigset_t *sigmask), + (fds, nfds, timeout, sigmask)) + #endif -- cgit v1.2.3