From f399623004bc8a19b8f076167c9858cb12bcf7a3 Mon Sep 17 00:00:00 2001 From: David Xu Date: Thu, 3 Jul 2003 13:36:29 +0000 Subject: If select() is only used for sleep, convert it to nanosleep, it only need purely wait in user space. --- lib/libkse/thread/thr_select.c | 13 +++++++++---- lib/libpthread/thread/thr_select.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c index 6714af02d1ecb..25be6a95be6e4 100644 --- a/lib/libkse/thread/thr_select.c +++ b/lib/libkse/thread/thr_select.c @@ -50,11 +50,16 @@ __select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { struct pthread *curthread = _get_curthread(); + struct timespec ts; int ret; - _thr_enter_cancellation_point(curthread); - ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout); - _thr_leave_cancellation_point(curthread); - + if (numfds == 0 && timeout != NULL) { + TIMEVAL_TO_TIMESPEC(timeout, &ts); + return nanosleep(&ts, NULL); + } else { + _thr_enter_cancellation_point(curthread); + ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout); + _thr_leave_cancellation_point(curthread); + } return ret; } diff --git a/lib/libpthread/thread/thr_select.c b/lib/libpthread/thread/thr_select.c index 6714af02d1ecb..25be6a95be6e4 100644 --- a/lib/libpthread/thread/thr_select.c +++ b/lib/libpthread/thread/thr_select.c @@ -50,11 +50,16 @@ __select(int numfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { struct pthread *curthread = _get_curthread(); + struct timespec ts; int ret; - _thr_enter_cancellation_point(curthread); - ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout); - _thr_leave_cancellation_point(curthread); - + if (numfds == 0 && timeout != NULL) { + TIMEVAL_TO_TIMESPEC(timeout, &ts); + return nanosleep(&ts, NULL); + } else { + _thr_enter_cancellation_point(curthread); + ret = __sys_select(numfds, readfds, writefds, exceptfds, timeout); + _thr_leave_cancellation_point(curthread); + } return ret; } -- cgit v1.2.3