summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_nanosleep.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2001-01-24 13:03:38 +0000
committerdeischen <deischen@FreeBSD.org>2001-01-24 13:03:38 +0000
commitee1de6a067c70fbd8cb73facd64c3b0b275f9f83 (patch)
tree71d2853de2f283028592fa4119320bab82c18d68 /lib/libpthread/thread/thr_nanosleep.c
parent274959d59337555267567d4bde9a5a841c47d84f (diff)
downloadFreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.zip
FreeBSD-src-ee1de6a067c70fbd8cb73facd64c3b0b275f9f83.tar.gz
Add weak definitions for wrapped system calls. In general:
_foo - wrapped system call foo - weak definition to _foo and for cancellation points: _foo - wrapped system call __foo - enter cancellation point, call _foo(), leave cancellation point foo - weak definition to __foo Change use of global _thread_run to call a function to get the currently running thread. Make all pthread_foo functions weak definitions to _pthread_foo, where _pthread_foo is the implementation. This allows an application to provide its own pthread functions. Provide slightly different versions of pthread_mutex_lock and pthread_mutex_init so that we can tell the difference between a libc mutex and an application mutex. Threads holding mutexes internal to libc should never be allowed to exit, call signal handlers, or cancel. Approved by: -arch
Diffstat (limited to 'lib/libpthread/thread/thr_nanosleep.c')
-rw-r--r--lib/libpthread/thread/thr_nanosleep.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/libpthread/thread/thr_nanosleep.c b/lib/libpthread/thread/thr_nanosleep.c
index 67dd08d..54349d4 100644
--- a/lib/libpthread/thread/thr_nanosleep.c
+++ b/lib/libpthread/thread/thr_nanosleep.c
@@ -33,14 +33,16 @@
*/
#include <stdio.h>
#include <errno.h>
-#ifdef _THREAD_SAFE
#include <pthread.h>
#include "pthread_private.h"
+#pragma weak nanosleep=__nanosleep
+
int
_nanosleep(const struct timespec * time_to_sleep,
struct timespec * time_remaining)
{
+ struct pthread *curthread = _get_curthread();
int ret = 0;
struct timespec current_time;
struct timespec current_time1;
@@ -63,16 +65,16 @@ _nanosleep(const struct timespec * time_to_sleep,
TIMEVAL_TO_TIMESPEC(&tv, &current_time);
/* Calculate the time for the current thread to wake up: */
- _thread_run->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
- _thread_run->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
+ curthread->wakeup_time.tv_sec = current_time.tv_sec + time_to_sleep->tv_sec;
+ curthread->wakeup_time.tv_nsec = current_time.tv_nsec + time_to_sleep->tv_nsec;
/* Check if the nanosecond field has overflowed: */
- if (_thread_run->wakeup_time.tv_nsec >= 1000000000) {
+ if (curthread->wakeup_time.tv_nsec >= 1000000000) {
/* Wrap the nanosecond field: */
- _thread_run->wakeup_time.tv_sec += 1;
- _thread_run->wakeup_time.tv_nsec -= 1000000000;
+ curthread->wakeup_time.tv_sec += 1;
+ curthread->wakeup_time.tv_nsec -= 1000000000;
}
- _thread_run->interrupted = 0;
+ curthread->interrupted = 0;
/* Reschedule the current thread to sleep: */
_thread_kern_sched_state(PS_SLEEP_WAIT, __FILE__, __LINE__);
@@ -118,7 +120,7 @@ _nanosleep(const struct timespec * time_to_sleep,
}
/* Check if the sleep was interrupted: */
- if (_thread_run->interrupted) {
+ if (curthread->interrupted) {
/* Return an EINTR error : */
errno = EINTR;
ret = -1;
@@ -128,7 +130,7 @@ _nanosleep(const struct timespec * time_to_sleep,
}
int
-nanosleep(const struct timespec * time_to_sleep, struct timespec *
+__nanosleep(const struct timespec * time_to_sleep, struct timespec *
time_remaining)
{
int ret;
@@ -139,4 +141,3 @@ nanosleep(const struct timespec * time_to_sleep, struct timespec *
return ret;
}
-#endif
OpenPOWER on IntegriCloud