As long as we have a knob to force system scope threads, why not have
a knob to force process scope threads. If the environment variable LIBPTHREAD_PROCESS_SCOPE is set, force all threads to be process scope threads regardless of how the application creates them. If LIBPTHREAD_SYSTEM_SCOPE is set (forcing system scope threads), it overrides LIBPTHREAD_PROCESS_SCOPE. $ # To force system scope threads $ LIBPTHREAD_SYSTEM_SCOPE=anything threaded_app $ # To force process scope threads $ LIBPTHREAD_PROCESS_SCOPE=anything threaded_app
This commit is contained in:
parent
313745d2ad
commit
b9de27c005
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=133563
@ -126,8 +126,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (_thread_scope_system != 0)
|
||||
if (_thread_scope_system > 0)
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
else if ((_thread_scope_system < 0)
|
||||
&& (thread != &_thr_sig_daemon))
|
||||
new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
if (create_stack(&new_thread->attr) != 0) {
|
||||
/* Insufficient memory to create a stack: */
|
||||
ret = EAGAIN;
|
||||
|
@ -126,8 +126,8 @@ _pthread_exit(void *status)
|
||||
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
|
||||
/* Use thread_list_lock */
|
||||
_thread_active_threads--;
|
||||
if ((_thread_scope_system == 0 && _thread_active_threads == 1) ||
|
||||
(_thread_scope_system != 0 && _thread_active_threads == 0)) {
|
||||
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);
|
||||
|
@ -258,7 +258,7 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kse_init();
|
||||
|
||||
/* Initialize the initial kse and kseg. */
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system);
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system > 0);
|
||||
if (_kse_initial == NULL)
|
||||
PANIC("Can't allocate initial kse.");
|
||||
_kse_initial->k_kseg = _kseg_alloc(NULL);
|
||||
@ -469,6 +469,8 @@ init_private(void)
|
||||
#else
|
||||
if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
|
||||
_thread_scope_system = 1;
|
||||
else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL)
|
||||
_thread_scope_system = -1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -75,8 +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.
|
||||
*/
|
||||
#define MAX_CACHED_KSES ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#define MAX_CACHED_KSEGS ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#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
|
||||
@ -407,7 +407,7 @@ _kse_setthreaded(int threaded)
|
||||
*/
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
if (_thread_scope_system == 0) {
|
||||
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;
|
||||
@ -439,7 +439,7 @@ _kse_setthreaded(int threaded)
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_lwp;
|
||||
_thread_activated = 1;
|
||||
|
||||
if (_thread_scope_system == 0) {
|
||||
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);
|
||||
|
@ -126,8 +126,11 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
*/
|
||||
}
|
||||
}
|
||||
if (_thread_scope_system != 0)
|
||||
if (_thread_scope_system > 0)
|
||||
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
|
||||
else if ((_thread_scope_system < 0)
|
||||
&& (thread != &_thr_sig_daemon))
|
||||
new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
|
||||
if (create_stack(&new_thread->attr) != 0) {
|
||||
/* Insufficient memory to create a stack: */
|
||||
ret = EAGAIN;
|
||||
|
@ -126,8 +126,8 @@ _pthread_exit(void *status)
|
||||
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
|
||||
/* Use thread_list_lock */
|
||||
_thread_active_threads--;
|
||||
if ((_thread_scope_system == 0 && _thread_active_threads == 1) ||
|
||||
(_thread_scope_system != 0 && _thread_active_threads == 0)) {
|
||||
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);
|
||||
|
@ -258,7 +258,7 @@ _libpthread_init(struct pthread *curthread)
|
||||
_kse_init();
|
||||
|
||||
/* Initialize the initial kse and kseg. */
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system);
|
||||
_kse_initial = _kse_alloc(NULL, _thread_scope_system > 0);
|
||||
if (_kse_initial == NULL)
|
||||
PANIC("Can't allocate initial kse.");
|
||||
_kse_initial->k_kseg = _kseg_alloc(NULL);
|
||||
@ -469,6 +469,8 @@ init_private(void)
|
||||
#else
|
||||
if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
|
||||
_thread_scope_system = 1;
|
||||
else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL)
|
||||
_thread_scope_system = -1;
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -75,8 +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.
|
||||
*/
|
||||
#define MAX_CACHED_KSES ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#define MAX_CACHED_KSEGS ((_thread_scope_system == 0) ? 50 : 100)
|
||||
#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
|
||||
@ -407,7 +407,7 @@ _kse_setthreaded(int threaded)
|
||||
*/
|
||||
_kse_initial->k_flags |= KF_STARTED;
|
||||
|
||||
if (_thread_scope_system == 0) {
|
||||
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;
|
||||
@ -439,7 +439,7 @@ _kse_setthreaded(int threaded)
|
||||
_kse_initial->k_kcb->kcb_kmbx.km_lwp;
|
||||
_thread_activated = 1;
|
||||
|
||||
if (_thread_scope_system == 0) {
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user