summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2003-07-03 13:36:29 +0000
committerdavidxu <davidxu@FreeBSD.org>2003-07-03 13:36:29 +0000
commit2d545c0325ebd6225a22298a5cffc0570a56fb16 (patch)
tree3a9c8ea250328dbe4e64a79c6913d068fb2ad1e1 /lib
parentfa35478dfe8e5268d7fb4da151147ab3de075bef (diff)
downloadFreeBSD-src-2d545c0325ebd6225a22298a5cffc0570a56fb16.zip
FreeBSD-src-2d545c0325ebd6225a22298a5cffc0570a56fb16.tar.gz
If select() is only used for sleep, convert it to nanosleep,
it only need purely wait in user space.
Diffstat (limited to 'lib')
-rw-r--r--lib/libkse/thread/thr_select.c13
-rw-r--r--lib/libpthread/thread/thr_select.c13
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c
index 6714af0..25be6a9 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 6714af0..25be6a9 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;
}
OpenPOWER on IntegriCloud