Sweep through pthread locking and use the new locking primitives for
libthr.
This commit is contained in:
parent
2234d5bea2
commit
dbc6f4c07d
@ -80,12 +80,12 @@ retry:
|
||||
* Disconnect the thread from the joinee:
|
||||
*/
|
||||
if ((joined = pthread->join_status.thread) != NULL) {
|
||||
if (_spintrylock(&joined->lock) == EBUSY) {
|
||||
if (THR_TRYLOCK(&joined->lock) == EBUSY) {
|
||||
_thread_critical_exit(pthread);
|
||||
goto retry;
|
||||
}
|
||||
pthread->join_status.thread->joiner = NULL;
|
||||
_spinunlock(&joined->lock);
|
||||
THR_UNLOCK(&joined->lock);
|
||||
joined = pthread->join_status.thread = NULL;
|
||||
}
|
||||
pthread->cancelflags |= PTHREAD_CANCELLING;
|
||||
|
@ -44,10 +44,10 @@ _pthread_detach(pthread_t pthread)
|
||||
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
|
||||
return (EINVAL);
|
||||
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
|
||||
if (pthread->attr.flags & PTHREAD_DETACHED) {
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ _pthread_detach(pthread_t pthread)
|
||||
_thread_critical_exit(joiner);
|
||||
}
|
||||
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ retry:
|
||||
/* Check if there is a thread joining this one: */
|
||||
if (curthread->joiner != NULL) {
|
||||
pthread = curthread->joiner;
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
curthread->joiner = NULL;
|
||||
|
||||
/* Make the joining thread runnable: */
|
||||
@ -156,7 +156,7 @@ retry:
|
||||
pthread->join_status.ret = curthread->ret;
|
||||
pthread->join_status.error = 0;
|
||||
pthread->join_status.thread = NULL;
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
|
||||
/* Make this thread collectable by the garbage collector. */
|
||||
PTHREAD_ASSERT(((curthread->attr.flags & PTHREAD_DETACHED) ==
|
||||
|
@ -106,7 +106,7 @@ _thread_gc(pthread_addr_t arg)
|
||||
if (pthread == _thread_initial)
|
||||
continue;
|
||||
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
|
||||
/*
|
||||
* Check if the stack was not specified by
|
||||
@ -128,7 +128,7 @@ _thread_gc(pthread_addr_t arg)
|
||||
* it on the dead thread list.
|
||||
*/
|
||||
if ((pthread->attr.flags & PTHREAD_DETACHED) == 0) {
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ _thread_gc(pthread_addr_t arg)
|
||||
*/
|
||||
pthread_cln = pthread;
|
||||
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
|
||||
/*
|
||||
* Retire the architecture specific id so it may be
|
||||
|
@ -33,6 +33,7 @@
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include "thr_private.h"
|
||||
|
||||
__weak_reference(_pthread_join, pthread_join);
|
||||
@ -69,7 +70,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
THREAD_LIST_LOCK;
|
||||
TAILQ_FOREACH(thread, &_thread_list, tle)
|
||||
if (thread == pthread) {
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
*/
|
||||
TAILQ_FOREACH(thread, &_dead_list, dle)
|
||||
if (thread == pthread) {
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
if (thread == NULL ||
|
||||
((pthread->attr.flags & PTHREAD_DETACHED) != 0)) {
|
||||
if (thread != NULL)
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
THREAD_LIST_UNLOCK;
|
||||
DEAD_LIST_UNLOCK;
|
||||
ret = ESRCH;
|
||||
@ -97,7 +98,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
if (pthread->joiner != NULL) {
|
||||
/* Multiple joiners are not supported. */
|
||||
/* XXXTHR - support multiple joiners. */
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
THREAD_LIST_UNLOCK;
|
||||
DEAD_LIST_UNLOCK;
|
||||
ret = ENOTSUP;
|
||||
@ -109,7 +110,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
if (pthread->state != PS_DEAD) {
|
||||
/* Set the running thread to be the joiner: */
|
||||
pthread->joiner = curthread;
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
_thread_critical_enter(curthread);
|
||||
|
||||
/* Keep track of which thread we're joining to: */
|
||||
@ -159,7 +160,7 @@ _pthread_join(pthread_t pthread, void **thread_return)
|
||||
|
||||
/* Make the thread collectable by the garbage collector. */
|
||||
pthread->attr.flags |= PTHREAD_DETACHED;
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
THREAD_LIST_UNLOCK;
|
||||
if (pthread_cond_signal(&_gc_cond) != 0)
|
||||
PANIC("Cannot signal gc cond");
|
||||
|
@ -56,13 +56,13 @@ void
|
||||
_thread_critical_enter(pthread_t pthread)
|
||||
{
|
||||
_thread_sigblock();
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
}
|
||||
|
||||
void
|
||||
_thread_critical_exit(pthread_t pthread)
|
||||
{
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
_thread_sigunblock();
|
||||
}
|
||||
|
||||
|
@ -1263,9 +1263,9 @@ _mutex_lock_backout(pthread_t pthread)
|
||||
/* _thread_kern_sig_defer();*/
|
||||
|
||||
/* XXX - Necessary to obey lock order */
|
||||
_SPINLOCK(&pthread->lock);
|
||||
THR_LOCK(&pthread->lock);
|
||||
mutex = pthread->data.mutex;
|
||||
_SPINUNLOCK(&pthread->lock);
|
||||
THR_UNLOCK(&pthread->lock);
|
||||
|
||||
_SPINLOCK(&mutex->lock);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user