aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Xu <davidxu@FreeBSD.org>2003-07-03 13:36:29 +0000
committerDavid Xu <davidxu@FreeBSD.org>2003-07-03 13:36:29 +0000
commitf399623004bc8a19b8f076167c9858cb12bcf7a3 (patch)
tree3a9c8ea250328dbe4e64a79c6913d068fb2ad1e1
parente921a3c976e6f2841902088af2af85448881ce48 (diff)
downloadsrc-f399623004bc8a19b8f076167c9858cb12bcf7a3.tar.gz
src-f399623004bc8a19b8f076167c9858cb12bcf7a3.zip
If select() is only used for sleep, convert it to nanosleep,
it only need purely wait in user space.
Notes
Notes: svn path=/head/; revision=117197
-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 6714af02d1ec..25be6a95be6e 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 6714af02d1ec..25be6a95be6e 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;
}