summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_create.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2003-05-24 02:29:25 +0000
committerdeischen <deischen@FreeBSD.org>2003-05-24 02:29:25 +0000
commitdc5114efb5a7accba1140bb50db1def228a37531 (patch)
treee99d3167d044ff37cf6b26fa4f4fe83140c8af79 /lib/libpthread/thread/thr_create.c
parentd8dec9f72fc70ddb0f6dc6547bc8207a1061187d (diff)
downloadFreeBSD-src-dc5114efb5a7accba1140bb50db1def228a37531.zip
FreeBSD-src-dc5114efb5a7accba1140bb50db1def228a37531.tar.gz
Change low-level locking a bit so that we can tell if
a lock is being waitied on. Fix a races in join and cancellation. When trying to wait on a CV and the library is not yet threaded, make it threaded so that waiting actually works. When trying to nanosleep() and we're not threaded, just call the system call nanosleep instead of adding the thread to the wait queue. Clean up adding/removing new threads to the "all threads queue", assigning them unique ids, and tracking how many active threads there are. Do it all when the thread is added to the scheduling queue instead of making pthread_create() know how to do it. Fix a race where a thread could be marked for signal delivery but it could be exited before we actually add the signal to it. Other minor cleanups and bug fixes. Submitted by: davidxu Approved by: re@ (blanket for libpthread)
Diffstat (limited to 'lib/libpthread/thread/thr_create.c')
-rw-r--r--lib/libpthread/thread/thr_create.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/lib/libpthread/thread/thr_create.c b/lib/libpthread/thread/thr_create.c
index 4cc1b6c..6b57f0e 100644
--- a/lib/libpthread/thread/thr_create.c
+++ b/lib/libpthread/thread/thr_create.c
@@ -44,8 +44,6 @@
#include "thr_private.h"
#include "libc_private.h"
-static u_int64_t next_uniqueid = 1;
-
#define OFF(f) offsetof(struct pthread, f)
int _thread_next_offset = OFF(tle.tqe_next);
int _thread_uniqueid_offset = OFF(uniqueid);
@@ -145,8 +143,13 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|| ((kseg = _kseg_alloc(curthread)) == NULL))) {
/* Insufficient memory to create a new KSE/KSEG: */
ret = EAGAIN;
- if (kse != NULL)
+#ifndef KMF_DONE
+#define KMF_DONE 0x04
+#endif
+ if (kse != NULL) {
+ kse->k_mbx.km_flags |= KMF_DONE;
_kse_free(curthread, kse);
+ }
if ((new_thread->attr.flags & THR_STACK_USER) == 0) {
crit = _kse_critical_enter();
curkse = _get_curkse();
@@ -161,7 +164,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
else {
if (kseg != NULL) {
/* Add the KSE to the KSEG's list of KSEs. */
- TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_qe);
+ TAILQ_INSERT_HEAD(&kseg->kg_kseq, kse, k_kgqe);
+ kseg->kg_ksecount = 1;
kse->k_kseg = kseg;
kse->k_schedq = &kseg->kg_schedq;
}
@@ -286,30 +290,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
kse->k_mbx.km_curthread = NULL;
}
- crit = _kse_critical_enter();
- KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock);
- /*
- * Initialise the unique id which GDB uses to
- * track threads.
- */
- new_thread->uniqueid = next_uniqueid++;
- /* Add the thread to the linked list of all threads: */
- THR_LIST_ADD(new_thread);
- KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock);
-
/*
* Schedule the new thread starting a new KSEG/KSE
* pair if necessary.
*/
ret = _thr_schedule_add(curthread, new_thread);
- if (ret != 0) {
- KSE_LOCK_ACQUIRE(curthread->kse,
- &_thread_list_lock);
- THR_LIST_REMOVE(new_thread);
- KSE_LOCK_RELEASE(curthread->kse,
- &_thread_list_lock);
- }
- _kse_critical_leave(crit);
if (ret != 0)
free_thread(curthread, new_thread);
@@ -341,7 +326,7 @@ create_stack(struct pthread_attr *pattr)
/* Check if a stack was specified in the thread attributes: */
if ((pattr->stackaddr_attr) != NULL) {
pattr->guardsize_attr = 0;
- pattr->flags = THR_STACK_USER;
+ pattr->flags |= THR_STACK_USER;
ret = 0;
}
else
OpenPOWER on IntegriCloud