summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authormtm <mtm@FreeBSD.org>2003-05-26 00:37:07 +0000
committermtm <mtm@FreeBSD.org>2003-05-26 00:37:07 +0000
commit23f766944414893832e8a3d10afbceded194916f (patch)
tree4913d71c40094f5da6427b152c90be36f35dfdd6 /lib/libthr
parent3440accd67bef89b04b9c16c578fd05c6de445b3 (diff)
downloadFreeBSD-src-23f766944414893832e8a3d10afbceded194916f.zip
FreeBSD-src-23f766944414893832e8a3d10afbceded194916f.tar.gz
Decouple the thread stack [de]allocating functions from the 'dead threads list'
lock. It's not really necessary and we don't need the added complexity or potential for deadlocks. Approved by: re/blanket libthr
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_create.c5
-rw-r--r--lib/libthr/thread/thr_gc.c2
-rw-r--r--lib/libthr/thread/thr_private.h8
-rw-r--r--lib/libthr/thread/thr_stack.c8
4 files changed, 16 insertions, 7 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c
index 5b0158d..c86f244 100644
--- a/lib/libthr/thread/thr_create.c
+++ b/lib/libthr/thread/thr_create.c
@@ -119,11 +119,10 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->arch_id = _set_curthread(&new_thread->ctx, new_thread, &ret);
if (ret != 0) {
if (pattr->stackaddr_attr == NULL) {
- /* XXX - We really need to decouple from this lock */
- DEAD_LIST_LOCK;
+ STACK_LOCK;
_thread_stack_free(new_thread->stack,
pattr->stacksize_attr, pattr->guardsize_attr);
- DEAD_LIST_UNLOCK;
+ STACK_UNLOCK;
}
free(new_thread);
return (ret);
diff --git a/lib/libthr/thread/thr_gc.c b/lib/libthr/thread/thr_gc.c
index d491bff..9e26314 100644
--- a/lib/libthr/thread/thr_gc.c
+++ b/lib/libthr/thread/thr_gc.c
@@ -113,6 +113,7 @@ _thread_gc(pthread_addr_t arg)
* the caller to pthread_create() and has not
* been destroyed yet:
*/
+ STACK_LOCK;
if (pthread->attr.stackaddr_attr == NULL &&
pthread->stack != NULL) {
_thread_stack_free(pthread->stack,
@@ -120,6 +121,7 @@ _thread_gc(pthread_addr_t arg)
pthread->attr.guardsize_attr);
pthread->stack = NULL;
}
+ STACK_UNLOCK;
/*
* If the thread has not been detached, leave
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index d8e37b4..7bf1b14 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -578,6 +578,14 @@ SCLASS void *_usrstack
;
#endif
+SCLASS spinlock_t stack_lock
+#ifdef GLOBAL_PTHREAD_PRIVATE
+= _SPINLOCK_INITIALIZER
+#endif
+;
+#define STACK_LOCK _SPINLOCK(&stack_lock);
+#define STACK_UNLOCK _SPINUNLOCK(&stack_lock);
+
/* List of all threads: */
SCLASS TAILQ_HEAD(, pthread) _thread_list
#ifdef GLOBAL_PTHREAD_PRIVATE
diff --git a/lib/libthr/thread/thr_stack.c b/lib/libthr/thread/thr_stack.c
index 28b396b..b4063ad 100644
--- a/lib/libthr/thread/thr_stack.c
+++ b/lib/libthr/thread/thr_stack.c
@@ -144,7 +144,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
* Use the garbage collector mutex for synchronization of the
* spare stack list.
*/
- DEAD_LIST_LOCK;
+ STACK_LOCK;
if ((spare_stack = LIST_FIRST(&_dstackq)) != NULL) {
/* Use the spare stack. */
@@ -153,7 +153,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
}
/* Unlock the garbage collector mutex. */
- DEAD_LIST_UNLOCK;
+ STACK_UNLOCK;
}
/*
* The user specified a non-default stack and/or guard size, so try to
@@ -165,7 +165,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
* Use the garbage collector mutex for synchronization of the
* spare stack list.
*/
- DEAD_LIST_LOCK;
+ STACK_LOCK;
LIST_FOREACH(spare_stack, &_mstackq, qe) {
if (spare_stack->stacksize == stack_size &&
@@ -177,7 +177,7 @@ _thread_stack_alloc(size_t stacksize, size_t guardsize)
}
/* Unlock the garbage collector mutex. */
- DEAD_LIST_UNLOCK;
+ STACK_UNLOCK;
}
/* Check if a stack was not allocated from a stack cache: */
OpenPOWER on IntegriCloud