summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread/uthread_nanosleep.c
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2001-12-31 18:23:16 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2001-12-31 18:23:16 +0000
commit0d227c4e86fd246a7da6e9edb97e6bef77779729 (patch)
treea8bb77358150faa0d0372965e313bd2ff914d54c /lib/libpthread/uthread/uthread_nanosleep.c
parentc46895d8d7573ae0e7da97af7986b5630e355e97 (diff)
More changes from FreeBSD, including:
o Only poll file descriptors when needed. o Change the way timing is achieved, counting scheduling ticks instead of calculating the elapsed time via gettimeofday(). o Prevent an overflow when polling. o Use curthread instead of _thread_run. o Remove extra spaces; indent.
Diffstat (limited to 'lib/libpthread/uthread/uthread_nanosleep.c')
-rw-r--r--lib/libpthread/uthread/uthread_nanosleep.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/libpthread/uthread/uthread_nanosleep.c b/lib/libpthread/uthread/uthread_nanosleep.c
index 4518a13e91c..26a26c1c678 100644
--- a/lib/libpthread/uthread/uthread_nanosleep.c
+++ b/lib/libpthread/uthread/uthread_nanosleep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_nanosleep.c,v 1.6 2001/08/21 19:24:53 fgsch Exp $ */
+/* $OpenBSD: uthread_nanosleep.c,v 1.7 2001/12/31 18:23:15 fgsch Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -59,8 +59,12 @@ nanosleep(const struct timespec * time_to_sleep,
errno = EINVAL;
ret = -1;
} else {
- /* Get the current time: */
- gettimeofday(&tv, NULL);
+ /*
+ * As long as we're going to get the time of day, we
+ * might as well store it in the global time of day:
+ */
+ gettimeofday((struct timeval *) &_sched_tod, NULL);
+ GET_CURRENT_TOD(tv);
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
@@ -78,8 +82,12 @@ nanosleep(const struct timespec * time_to_sleep,
/* Reschedule the current thread to sleep: */
_thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__);
- /* Get the current time: */
- gettimeofday(&tv, NULL);
+ /*
+ * As long as we're going to get the time of day, we
+ * might as well store it in the global time of day:
+ */
+ gettimeofday((struct timeval *) &_sched_tod, NULL);
+ GET_CURRENT_TOD(tv);
TIMEVAL_TO_TIMESPEC(&tv, &current_time1);
/* Calculate the remaining time to sleep: */