- Remove variable _thr_scope_system, all threads are system scope.

- Rename _thr_smp_cpus to boolean variable _thr_is_smp.
- Define CPU_SPINWAIT macro for each arch, only X86 supports it.
This commit is contained in:
David Xu 2006-12-15 11:52:01 +00:00
parent 76682b268e
commit d99f6dac14
10 changed files with 19 additions and 25 deletions

View File

@ -36,7 +36,8 @@
#include <stddef.h>
#include <sys/types.h>
#include <machine/sysarch.h>
#include <ucontext.h>
#define CPU_SPINWAIT __asm __volatile("pause")
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)

View File

@ -36,6 +36,7 @@
#include <machine/sysarch.h>
#include <stddef.h>
#define CPU_SPINWAIT
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
/*

View File

@ -37,6 +37,8 @@
#include <sys/types.h>
#include <machine/sysarch.h>
#define CPU_SPINWAIT __asm __volatile("pause")
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
/*

View File

@ -31,6 +31,8 @@
#include <stddef.h>
#define CPU_SPINWAIT
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
/*

View File

@ -36,6 +36,8 @@
#include <stddef.h>
#include <sys/types.h>
#define CPU_SPINWAIT
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
#define TP_OFFSET 0x7008

View File

@ -35,6 +35,8 @@
#include <stddef.h>
#define CPU_SPINWAIT
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
/*

View File

@ -86,11 +86,6 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->attr.sched_policy = curthread->attr.sched_policy;
}
if (_thr_scope_system > 0)
new_thread->attr.flags |= PTHREAD_SCOPE_SYSTEM;
else if (_thr_scope_system < 0)
new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
new_thread->tid = TID_TERMINATED;
if (create_stack(&new_thread->attr) != 0) {

View File

@ -58,7 +58,6 @@
char *_usrstack;
struct pthread *_thr_initial;
int _thr_scope_system;
int _libthr_debug;
int _thread_event_mask;
struct pthread *_thread_last_event;
@ -99,7 +98,7 @@ struct pthread_cond_attr _pthread_condattr_default = {
};
pid_t _thr_pid;
int _thr_smp_cpus = 1;
int _thr_is_smp = 0;
size_t _thr_guard_default;
size_t _thr_stack_default = THR_STACK_DEFAULT;
size_t _thr_stack_initial = THR_STACK_INITIAL;
@ -446,22 +445,15 @@ init_private(void)
len = sizeof (_usrstack);
if (sysctl(mib, 2, &_usrstack, &len, NULL, 0) == -1)
PANIC("Cannot get kern.usrstack from sysctl");
len = sizeof(_thr_smp_cpus);
sysctlbyname("kern.smp.cpus", &_thr_smp_cpus, &len, NULL, 0);
len = sizeof(_thr_is_smp);
sysctlbyname("kern.smp.cpus", &_thr_is_smp, &len, NULL, 0);
_thr_is_smp = (_thr_is_smp > 1);
_thr_page_size = getpagesize();
_thr_guard_default = _thr_page_size;
_pthread_attr_default.guardsize_attr = _thr_guard_default;
_pthread_attr_default.stacksize_attr = _thr_stack_default;
TAILQ_INIT(&_thr_atfork_list);
#ifdef SYSTEM_SCOPE_ONLY
_thr_scope_system = 1;
#else
if (getenv("LIBPTHREAD_SYSTEM_SCOPE") != NULL)
_thr_scope_system = 1;
else if (getenv("LIBPTHREAD_PROCESS_SCOPE") != NULL)
_thr_scope_system = -1;
#endif
}
init_once = 1;
}

View File

@ -549,7 +549,6 @@ extern int __isthreaded;
extern char *_usrstack __hidden;
extern struct pthread *_thr_initial __hidden;
extern int _thr_scope_system __hidden;
/* For debugger */
extern int _libthr_debug;
@ -578,7 +577,7 @@ extern struct pthread_cond_attr _pthread_condattr_default __hidden;
extern struct pthread_prio _thr_priorities[] __hidden;
extern pid_t _thr_pid __hidden;
extern int _thr_smp_cpus __hidden;
extern int _thr_is_smp __hidden;
extern size_t _thr_guard_default __hidden;
extern size_t _thr_stack_default __hidden;

View File

@ -104,13 +104,11 @@ _pthread_spin_lock(pthread_spinlock_t *lock)
count = SPIN_COUNT;
while ((ret = THR_UMUTEX_TRYLOCK(curthread, &lck->s_lock)) != 0) {
while (lck->s_lock.m_owner) {
if (_thr_smp_cpus <= 1) {
if (_thr_is_smp) {
_pthread_yield();
} else {
#if defined(__i386__) || defined(__x86_64__)
/* tell cpu we are spinning */
__asm __volatile("pause");
#endif
CPU_SPINWAIT;
if (--count <= 0) {
count = SPIN_COUNT;
_pthread_yield();