diff options
author | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-01-24 13:03:38 +0000 |
commit | ee1de6a067c70fbd8cb73facd64c3b0b275f9f83 (patch) | |
tree | 71d2853de2f283028592fa4119320bab82c18d68 /lib/libkse/thread/thr_join.c | |
parent | 274959d59337555267567d4bde9a5a841c47d84f (diff) | |
download | FreeBSD-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/libkse/thread/thr_join.c')
-rw-r--r-- | lib/libkse/thread/thr_join.c | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/libkse/thread/thr_join.c b/lib/libkse/thread/thr_join.c index b4a7c61..2615f73 100644 --- a/lib/libkse/thread/thr_join.c +++ b/lib/libkse/thread/thr_join.c @@ -32,13 +32,15 @@ * $FreeBSD$ */ #include <errno.h> -#ifdef _THREAD_SAFE #include <pthread.h> #include "pthread_private.h" +#pragma weak pthread_join=_pthread_join + int -pthread_join(pthread_t pthread, void **thread_return) +_pthread_join(pthread_t pthread, void **thread_return) { + struct pthread *curthread = _get_curthread(); int ret = 0; _thread_enter_cancellation_point(); @@ -51,7 +53,7 @@ pthread_join(pthread_t pthread, void **thread_return) } /* Check if the caller has specified itself: */ - if (pthread == _thread_run) { + if (pthread == curthread) { /* Avoid a deadlock condition: */ _thread_leave_cancellation_point(); return(EDEADLK); @@ -72,7 +74,7 @@ pthread_join(pthread_t pthread, void **thread_return) /* Check if the thread is not dead: */ else if (pthread->state != PS_DEAD) { - PTHREAD_ASSERT_NOT_IN_SYNCQ(_thread_run); + PTHREAD_ASSERT_NOT_IN_SYNCQ(curthread); /* * Enter a loop in case this thread is woken prematurely @@ -80,7 +82,7 @@ pthread_join(pthread_t pthread, void **thread_return) */ for (;;) { /* Clear the interrupted flag: */ - _thread_run->interrupted = 0; + curthread->interrupted = 0; /* * Protect against being context switched out while @@ -90,25 +92,25 @@ pthread_join(pthread_t pthread, void **thread_return) /* Add the running thread to the join queue: */ TAILQ_INSERT_TAIL(&(pthread->join_queue), - _thread_run, sqe); - _thread_run->flags |= PTHREAD_FLAGS_IN_JOINQ; - _thread_run->data.thread = pthread; + curthread, sqe); + curthread->flags |= PTHREAD_FLAGS_IN_JOINQ; + curthread->data.thread = pthread; /* Schedule the next thread: */ _thread_kern_sched_state(PS_JOIN, __FILE__, __LINE__); - if ((_thread_run->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) { + if ((curthread->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) { TAILQ_REMOVE(&(pthread->join_queue), - _thread_run, sqe); - _thread_run->flags &= ~PTHREAD_FLAGS_IN_JOINQ; + curthread, sqe); + curthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ; } - _thread_run->data.thread = NULL; + curthread->data.thread = NULL; _thread_kern_sig_undefer(); - if (_thread_run->interrupted != 0) { - if (_thread_run->continuation != NULL) - _thread_run->continuation(_thread_run); + if (curthread->interrupted != 0) { + if (curthread->continuation != NULL) + curthread->continuation(curthread); /* * This thread was interrupted, probably to * invoke a signal handler. Make sure the @@ -134,9 +136,9 @@ pthread_join(pthread_t pthread, void **thread_return) * by the thread we're joining to when it * exits or detaches: */ - ret = _thread_run->error; + ret = curthread->error; if ((ret == 0) && (thread_return != NULL)) - *thread_return = _thread_run->ret; + *thread_return = curthread->ret; /* We're done; break out of the loop. */ break; @@ -156,11 +158,12 @@ pthread_join(pthread_t pthread, void **thread_return) void _join_backout(pthread_t pthread) { + struct pthread *curthread = _get_curthread(); + _thread_kern_sig_defer(); if ((pthread->flags & PTHREAD_FLAGS_IN_JOINQ) != 0) { TAILQ_REMOVE(&pthread->data.thread->join_queue, pthread, sqe); - _thread_run->flags &= ~PTHREAD_FLAGS_IN_JOINQ; + curthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ; } _thread_kern_sig_undefer(); } -#endif |