summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2004-08-07 15:15:38 +0000
committerdeischen <deischen@FreeBSD.org>2004-08-07 15:15:38 +0000
commit628d407e8490a240e6c73a5e9994986e7a9ab164 (patch)
treea52137064a9f6d0ca8cd37a63377945781591df2 /lib/libpthread
parent51abab44f50b76d38ee3599125e7890346cd5279 (diff)
downloadFreeBSD-src-628d407e8490a240e6c73a5e9994986e7a9ab164.zip
FreeBSD-src-628d407e8490a240e6c73a5e9994986e7a9ab164.tar.gz
Add a way to force 1:1 mode for libpthread. To do this, define
LIBPTHREAD_SYSTEM_SCOPE in the environment. You can still force libpthread to be built in strictly 1:1 by adding -DSYSTEM_SCOPE_ONLY to CFLAGS. This is kept for archs that don't yet support M:N mode. Requested by: rwatson Reviewed by: davidxu
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/thread/thr_create.c5
-rw-r--r--lib/libpthread/thread/thr_exit.c7
-rw-r--r--lib/libpthread/thread/thr_init.c14
-rw-r--r--lib/libpthread/thread/thr_kern.c56
-rw-r--r--lib/libpthread/thread/thr_private.h1
5 files changed, 41 insertions, 42 deletions
diff --git a/lib/libpthread/thread/thr_create.c b/lib/libpthread/thread/thr_create.c
index 9682fcf..8c4592a 100644
--- a/lib/libpthread/thread/thr_create.c
+++ b/lib/libpthread/thread/thr_create.c
@@ -126,9 +126,8 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
*/
}
}
-#ifdef SYSTEM_SCOPE_ONLY
- new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
-#endif
+ if (_thread_scope_system != 0)
+ new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
if (create_stack(&new_thread->attr) != 0) {
/* Insufficient memory to create a stack: */
ret = EAGAIN;
diff --git a/lib/libpthread/thread/thr_exit.c b/lib/libpthread/thread/thr_exit.c
index 22aa875..ec8e9ec 100644
--- a/lib/libpthread/thread/thr_exit.c
+++ b/lib/libpthread/thread/thr_exit.c
@@ -126,11 +126,8 @@ _pthread_exit(void *status)
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
/* Use thread_list_lock */
_thread_active_threads--;
-#ifdef SYSTEM_SCOPE_ONLY
- if (_thread_active_threads == 0) {
-#else
- if (_thread_active_threads == 1) {
-#endif
+ if ((_thread_scope_system == 0 && _thread_active_threads == 1) ||
+ (_thread_scope_system != 0 && _thread_active_threads == 0)) {
KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
_kse_critical_leave(crit);
exit(0);
diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c
index 36e7e69..6c371b0 100644
--- a/lib/libpthread/thread/thr_init.c
+++ b/lib/libpthread/thread/thr_init.c
@@ -258,11 +258,7 @@ _libpthread_init(struct pthread *curthread)
_kse_init();
/* Initialize the initial kse and kseg. */
-#ifdef SYSTEM_SCOPE_ONLY
- _kse_initial = _kse_alloc(NULL, 1);
-#else
- _kse_initial = _kse_alloc(NULL, 0);
-#endif
+ _kse_initial = _kse_alloc(NULL, _thread_scope_system);
if (_kse_initial == NULL)
PANIC("Can't allocate initial kse.");
_kse_initial->k_kseg = _kseg_alloc(NULL);
@@ -467,6 +463,14 @@ init_private(void)
/* Clear pending signals and get the process signal mask. */
SIGEMPTYSET(_thr_proc_sigpending);
+ /* Are we in M:N mode (default) or 1:1 mode? */
+#ifdef SYSTEM_SCOPE_ONLY
+ _thread_scope_system = 1;
+#else
+ if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
+ _thread_scope_system = 1;
+#endif
+
/*
* _thread_list_lock and _kse_count are initialized
* by _kse_init()
diff --git a/lib/libpthread/thread/thr_kern.c b/lib/libpthread/thread/thr_kern.c
index c159f1b..ddcae89 100644
--- a/lib/libpthread/thread/thr_kern.c
+++ b/lib/libpthread/thread/thr_kern.c
@@ -75,13 +75,8 @@ __FBSDID("$FreeBSD$");
* same number of KSEs and KSE groups as threads. Once these levels are
* reached, any extra KSE and KSE groups will be free()'d.
*/
-#ifdef SYSTEM_SCOPE_ONLY
-#define MAX_CACHED_KSES 100
-#define MAX_CACHED_KSEGS 100
-#else
-#define MAX_CACHED_KSES 50
-#define MAX_CACHED_KSEGS 50
-#endif
+#define MAX_CACHED_KSES ((_thread_scope_system == 0) ? 50 : 100)
+#define MAX_CACHED_KSEGS ((_thread_scope_system == 0) ? 50 : 100)
#define KSE_SET_MBOX(kse, thrd) \
(kse)->k_kcb->kcb_kmbx.km_curthread = &(thrd)->tcb->tcb_tmbx
@@ -412,19 +407,20 @@ _kse_setthreaded(int threaded)
*/
_kse_initial->k_flags |= KF_STARTED;
-#ifdef SYSTEM_SCOPE_ONLY
- /*
- * For bound thread, kernel reads mailbox pointer once,
- * we'd set it here before calling kse_create
- */
- _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
- KSE_SET_MBOX(_kse_initial, _thr_initial);
- _kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
-#else
- _thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
- _kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
- _kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
-#endif
+ if (_thread_scope_system == 0) {
+ _thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
+ _kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
+ _kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
+ }
+ else {
+ /*
+ * For bound thread, kernel reads mailbox pointer
+ * once, we'd set it here before calling kse_create.
+ */
+ _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
+ KSE_SET_MBOX(_kse_initial, _thr_initial);
+ _kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
+ }
/*
* Locking functions in libc are required when there are
@@ -443,15 +439,17 @@ _kse_setthreaded(int threaded)
_kse_initial->k_kcb->kcb_kmbx.km_lwp;
_thread_activated = 1;
-#ifndef SYSTEM_SCOPE_ONLY
- /* Set current thread to initial thread */
- _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
- KSE_SET_MBOX(_kse_initial, _thr_initial);
- _thr_start_sig_daemon();
- _thr_setmaxconcurrency();
-#else
- __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
-#endif
+ if (_thread_scope_system == 0) {
+ /* Set current thread to initial thread */
+ _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
+ KSE_SET_MBOX(_kse_initial, _thr_initial);
+ _thr_start_sig_daemon();
+ _thr_setmaxconcurrency();
+ }
+ else {
+ __sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask,
+ NULL);
+ }
}
return (0);
}
diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h
index 7a3ae50..b2d1987 100644
--- a/lib/libpthread/thread/thr_private.h
+++ b/lib/libpthread/thread/thr_private.h
@@ -992,6 +992,7 @@ SCLASS struct pthread *_thr_initial SCLASS_PRESET(NULL);
/* For debugger */
SCLASS int _libkse_debug SCLASS_PRESET(0);
SCLASS int _thread_activated SCLASS_PRESET(0);
+SCLASS int _thread_scope_system SCLASS_PRESET(0);
/* List of all threads: */
SCLASS TAILQ_HEAD(, pthread) _thread_list
OpenPOWER on IntegriCloud