summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjeff <jeff@FreeBSD.org>2003-04-02 03:05:39 +0000
committerjeff <jeff@FreeBSD.org>2003-04-02 03:05:39 +0000
commitbb610376a5e993ec00e22a5e13f106b3b43d90f6 (patch)
tree3edb86617f8b88a54083b0eeb1e45c1b253d05e0 /lib
parentdc2ed57595804600bd48f7fa875694c5f01ec98d (diff)
downloadFreeBSD-src-bb610376a5e993ec00e22a5e13f106b3b43d90f6.zip
FreeBSD-src-bb610376a5e993ec00e22a5e13f106b3b43d90f6.tar.gz
- Define curthread as _get_curthread() and remove all direct calls to
_get_curthread(). This is similar to the kernel's curthread. Doing this saves stack overhead and is more convenient to the programmer. - Pass the pointer to the newly created thread to _thread_init(). - Remove _get_curthread_slow().
Diffstat (limited to 'lib')
-rw-r--r--lib/libthr/thread/thr_cancel.c10
-rw-r--r--lib/libthr/thread/thr_clean.c2
-rw-r--r--lib/libthr/thread/thr_cond.c6
-rw-r--r--lib/libthr/thread/thr_create.c16
-rw-r--r--lib/libthr/thread/thr_detach.c4
-rw-r--r--lib/libthr/thread/thr_exit.c3
-rw-r--r--lib/libthr/thread/thr_find_thread.c2
-rw-r--r--lib/libthr/thread/thr_gc.c1
-rw-r--r--lib/libthr/thread/thr_info.c1
-rw-r--r--lib/libthr/thread/thr_init.c16
-rw-r--r--lib/libthr/thread/thr_join.c1
-rw-r--r--lib/libthr/thread/thr_mutex.c13
-rw-r--r--lib/libthr/thread/thr_private.h14
-rw-r--r--lib/libthr/thread/thr_resume_np.c4
-rw-r--r--lib/libthr/thread/thr_self.c2
-rw-r--r--lib/libthr/thread/thr_sem.c2
-rw-r--r--lib/libthr/thread/thr_setschedparam.c2
-rw-r--r--lib/libthr/thread/thr_sig.c1
-rw-r--r--lib/libthr/thread/thr_spec.c11
-rw-r--r--lib/libthr/thread/thr_spinlock.c6
20 files changed, 21 insertions, 96 deletions
diff --git a/lib/libthr/thread/thr_cancel.c b/lib/libthr/thread/thr_cancel.c
index 0695fbc..ab4637c 100644
--- a/lib/libthr/thread/thr_cancel.c
+++ b/lib/libthr/thread/thr_cancel.c
@@ -15,7 +15,6 @@ int
_pthread_cancel(pthread_t pthread)
{
int ret;
- pthread_t curthread;
if ((ret = _find_thread(pthread)) != 0) {
/* NOTHING */
@@ -23,7 +22,6 @@ _pthread_cancel(pthread_t pthread)
|| (pthread->flags & PTHREAD_EXITING) != 0) {
ret = 0;
} else {
- curthread = _get_curthread();
GIANT_LOCK(curthread);
if (((pthread->cancelflags & PTHREAD_CANCEL_DISABLE) != 0) ||
@@ -94,7 +92,6 @@ _pthread_cancel(pthread_t pthread)
int
_pthread_setcancelstate(int state, int *oldstate)
{
- struct pthread *curthread = _get_curthread();
int ostate;
GIANT_LOCK(curthread);
@@ -127,7 +124,6 @@ _pthread_setcancelstate(int state, int *oldstate)
int
_pthread_setcanceltype(int type, int *oldtype)
{
- struct pthread *curthread = _get_curthread();
int otype;
GIANT_LOCK(curthread);
@@ -160,8 +156,6 @@ _pthread_setcanceltype(int type, int *oldtype)
void
_pthread_testcancel(void)
{
- struct pthread *curthread = _get_curthread();
-
GIANT_LOCK(curthread);
if (((curthread->cancelflags & PTHREAD_CANCEL_DISABLE) == 0) &&
((curthread->cancelflags & PTHREAD_CANCELLING) != 0) &&
@@ -183,8 +177,6 @@ _pthread_testcancel(void)
void
_thread_enter_cancellation_point(void)
{
- struct pthread *curthread = _get_curthread();
-
pthread_testcancel();
GIANT_LOCK(curthread);
@@ -195,8 +187,6 @@ _thread_enter_cancellation_point(void)
void
_thread_leave_cancellation_point(void)
{
- struct pthread *curthread = _get_curthread();
-
GIANT_LOCK(curthread);
curthread->cancelflags &= ~PTHREAD_AT_CANCEL_POINT;
GIANT_UNLOCK(curthread);
diff --git a/lib/libthr/thread/thr_clean.c b/lib/libthr/thread/thr_clean.c
index 8ae6b42..cc6f34f 100644
--- a/lib/libthr/thread/thr_clean.c
+++ b/lib/libthr/thread/thr_clean.c
@@ -43,7 +43,6 @@ __weak_reference(_pthread_cleanup_pop, pthread_cleanup_pop);
void
_pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
{
- struct pthread *curthread = _get_curthread();
struct pthread_cleanup *new;
if ((new = (struct pthread_cleanup *) malloc(sizeof(struct pthread_cleanup))) != NULL) {
@@ -58,7 +57,6 @@ _pthread_cleanup_push(void (*routine) (void *), void *routine_arg)
void
_pthread_cleanup_pop(int execute)
{
- struct pthread *curthread = _get_curthread();
struct pthread_cleanup *old;
if ((old = curthread->cleanup) != NULL) {
diff --git a/lib/libthr/thread/thr_cond.c b/lib/libthr/thread/thr_cond.c
index 6bee687..2ff97a0 100644
--- a/lib/libthr/thread/thr_cond.c
+++ b/lib/libthr/thread/thr_cond.c
@@ -137,8 +137,6 @@ _pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr)
int
_pthread_cond_destroy(pthread_cond_t *cond)
{
- struct pthread *curthread = _get_curthread();
-
if (cond == NULL || *cond == NULL)
return (EINVAL);
@@ -182,7 +180,6 @@ int
_pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
const struct timespec * abstime)
{
- struct pthread *curthread = _get_curthread();
struct timespec *time;
int rval = 0;
int done = 0;
@@ -340,7 +337,6 @@ _pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex,
int
_pthread_cond_signal(pthread_cond_t * cond)
{
- struct pthread *curthread = _get_curthread();
int rval = 0;
pthread_t pthread;
@@ -388,7 +384,6 @@ _pthread_cond_signal(pthread_cond_t * cond)
int
_pthread_cond_broadcast(pthread_cond_t * cond)
{
- struct pthread *curthread = _get_curthread();
int rval = 0;
pthread_t pthread;
@@ -442,7 +437,6 @@ _pthread_cond_broadcast(pthread_cond_t * cond)
void
_cond_wait_backout(pthread_t pthread)
{
- struct pthread *curthread = _get_curthread();
pthread_cond_t cond;
cond = pthread->data.cond;
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c
index 9a663b4..539a7c5 100644
--- a/lib/libthr/thread/thr_create.c
+++ b/lib/libthr/thread/thr_create.c
@@ -62,7 +62,6 @@ int
_pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void *(*start_routine) (void *), void *arg)
{
- struct pthread *curthread = _get_curthread();
struct itimerval itimer;
int f_gc = 0;
int ret = 0;
@@ -117,7 +116,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
getcontext(&new_thread->ctx);
new_thread->ctx.uc_stack.ss_sp = new_thread->stack;
new_thread->ctx.uc_stack.ss_size = pattr->stacksize_attr;
- makecontext(&new_thread->ctx, _thread_start, 1);
+ makecontext(&new_thread->ctx, _thread_start, 1, new_thread);
/* Copy the thread attributes: */
memcpy(&new_thread->attr, pattr, sizeof(struct pthread_attr));
@@ -209,19 +208,12 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
}
void
-_thread_start(void)
+_thread_start(pthread_t thread)
{
- struct pthread *curthread = _get_curthread_slow();
-
- curthread->arch_id = _set_curthread(curthread);
-
- if (_get_curthread() != curthread) {
- _thread_printf("%x - %x\n", _get_curthread(), curthread);
- abort();
- }
+ thread->arch_id = _set_curthread(thread);
/* Run the current thread's start routine with argument: */
- pthread_exit(curthread->start_routine(curthread->arg));
+ pthread_exit(thread->start_routine(thread->arg));
/* This point should never be reached. */
PANIC("Thread has resumed after exit");
diff --git a/lib/libthr/thread/thr_detach.c b/lib/libthr/thread/thr_detach.c
index ca1b473..b60dc5c 100644
--- a/lib/libthr/thread/thr_detach.c
+++ b/lib/libthr/thread/thr_detach.c
@@ -40,16 +40,12 @@ __weak_reference(_pthread_detach, pthread_detach);
int
_pthread_detach(pthread_t pthread)
{
- pthread_t curthread;
-
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
return (EINVAL);
if (pthread->attr.flags & PTHREAD_DETACHED)
return (EINVAL);
- curthread = _get_curthread();
-
pthread->attr.flags |= PTHREAD_DETACHED;
/*
diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c
index 2d791d2..f18c7c8 100644
--- a/lib/libthr/thread/thr_exit.c
+++ b/lib/libthr/thread/thr_exit.c
@@ -72,8 +72,6 @@ _thread_exit(char *fname, int lineno, char *string)
void
_thread_exit_cleanup(void)
{
- struct pthread *curthread = _get_curthread();
-
/*
* POSIX states that cancellation/termination of a thread should
* not release any visible resources (such as mutexes) and that
@@ -93,7 +91,6 @@ _thread_exit_cleanup(void)
void
_pthread_exit(void *status)
{
- struct pthread *curthread = _get_curthread();
pthread_t pthread;
/* Check if this thread is already in the process of exiting: */
diff --git a/lib/libthr/thread/thr_find_thread.c b/lib/libthr/thread/thr_find_thread.c
index a784818..1b34f2f 100644
--- a/lib/libthr/thread/thr_find_thread.c
+++ b/lib/libthr/thread/thr_find_thread.c
@@ -39,13 +39,11 @@
int
_find_thread(pthread_t pthread)
{
- pthread_t curthread;
pthread_t pthread1;
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
return(EINVAL);
- curthread = _get_curthread();
GIANT_LOCK(curthread);
/* Search for the specified thread: */
diff --git a/lib/libthr/thread/thr_gc.c b/lib/libthr/thread/thr_gc.c
index 987f88f..a33acce 100644
--- a/lib/libthr/thread/thr_gc.c
+++ b/lib/libthr/thread/thr_gc.c
@@ -46,7 +46,6 @@
pthread_addr_t
_thread_gc(pthread_addr_t arg)
{
- struct pthread *curthread = _get_curthread();
int f_debug;
int f_done = 0;
int ret;
diff --git a/lib/libthr/thread/thr_info.c b/lib/libthr/thread/thr_info.c
index 2e2f9de..b76d8e5 100644
--- a/lib/libthr/thread/thr_info.c
+++ b/lib/libthr/thread/thr_info.c
@@ -135,7 +135,6 @@ _thread_dump_info(void)
static void
dump_thread(int fd, pthread_t pthread, int long_version)
{
- struct pthread *curthread = _get_curthread();
char s[512];
int i;
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
index 266ff16..6a6fd45 100644
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -331,22 +331,6 @@ _thread_init(void)
PANIC("Failed to initialise garbage collector mutex or condvar");
}
-struct pthread *
-_get_curthread_slow(void)
-{
- struct pthread *td;
- thr_id_t id;
-
- if (_thread_initial == NULL)
- _thread_init();
-
- thr_self(&id);
- TAILQ_FOREACH(td, &_thread_list, tle)
- if (td->thr_id == id)
- return (td);
- return (NULL);
-}
-
/*
* Special start up code for NetBSD/Alpha
*/
diff --git a/lib/libthr/thread/thr_join.c b/lib/libthr/thread/thr_join.c
index ab46f0a..02d3142 100644
--- a/lib/libthr/thread/thr_join.c
+++ b/lib/libthr/thread/thr_join.c
@@ -40,7 +40,6 @@ __weak_reference(_pthread_join, pthread_join);
int
_pthread_join(pthread_t pthread, void **thread_return)
{
- struct pthread *curthread = _get_curthread();
int ret = 0;
pthread_t thread;
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 973fffa..67b137d 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -63,7 +63,7 @@
* Prototypes
*/
static inline int mutex_self_trylock(pthread_mutex_t);
-static inline int mutex_self_lock(pthread_t, pthread_mutex_t);
+static inline int mutex_self_lock(pthread_mutex_t);
static inline int mutex_unlock_common(pthread_mutex_t *, int);
static void mutex_priority_adjust(pthread_mutex_t);
static void mutex_rescan_owned (pthread_t, pthread_mutex_t);
@@ -300,7 +300,6 @@ init_static_private(pthread_mutex_t *mutex)
static int
mutex_trylock_common(pthread_mutex_t *mutex)
{
- struct pthread *curthread = _get_curthread();
int ret = 0;
PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
@@ -469,7 +468,6 @@ _pthread_mutex_trylock(pthread_mutex_t *mutex)
static int
mutex_lock_common(pthread_mutex_t * mutex)
{
- struct pthread *curthread = _get_curthread();
int ret = 0;
PTHREAD_ASSERT((mutex != NULL) && (*mutex != NULL),
@@ -517,7 +515,7 @@ mutex_lock_common(pthread_mutex_t * mutex)
(*mutex), m_qe);
} else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_lock(curthread, *mutex);
+ ret = mutex_self_lock(*mutex);
else {
/*
* Join the queue of threads waiting to lock
@@ -571,7 +569,7 @@ mutex_lock_common(pthread_mutex_t * mutex)
(*mutex), m_qe);
} else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_lock(curthread, *mutex);
+ ret = mutex_self_lock(*mutex);
else {
/*
* Join the queue of threads waiting to lock
@@ -637,7 +635,7 @@ mutex_lock_common(pthread_mutex_t * mutex)
TAILQ_INSERT_TAIL(&curthread->mutexq,
(*mutex), m_qe);
} else if ((*mutex)->m_owner == curthread)
- ret = mutex_self_lock(curthread, *mutex);
+ ret = mutex_self_lock(*mutex);
else {
/*
* Join the queue of threads waiting to lock
@@ -802,7 +800,7 @@ mutex_self_trylock(pthread_mutex_t mutex)
}
static inline int
-mutex_self_lock(pthread_t curthread, pthread_mutex_t mutex)
+mutex_self_lock(pthread_mutex_t mutex)
{
int ret = 0;
@@ -844,7 +842,6 @@ mutex_self_lock(pthread_t curthread, pthread_mutex_t mutex)
static inline int
mutex_unlock_common(pthread_mutex_t * mutex, int add_reference)
{
- struct pthread *curthread = _get_curthread();
int ret = 0;
if (mutex == NULL || *mutex == NULL) {
diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 9f4fcc0..7cc10e3 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -76,6 +76,11 @@
#define stderr_debug(args...) _thread_printf(STDOUT_FILENO, args)
/*
+ * Currently executing thread.
+ */
+#define curthread _get_curthread()
+
+/*
* State change macro without scheduling queue change:
*/
#define PTHREAD_SET_STATE(thrd, newstate) do { \
@@ -665,8 +670,8 @@ SCLASS volatile int _spinblock_count
* And, should we climb the beanstalk,
* We'll meet his brother, Giant.
*/
-void GIANT_LOCK(pthread_t curthread);
-void GIANT_UNLOCK(pthread_t curthread);
+void GIANT_LOCK(pthread_t);
+void GIANT_UNLOCK(pthread_t);
/* Undefine the storage class specifier: */
#undef SCLASS
@@ -680,8 +685,7 @@ char *__ttyname_r_basic(int, char *, size_t);
char *ttyname_r(int, char *, size_t);
void _cond_wait_backout(pthread_t);
int _find_thread(pthread_t);
-struct pthread *_get_curthread_slow(void);
-struct pthread *_get_curthread(void);
+pthread_t _get_curthread(void);
void *_set_curthread(struct pthread *);
void _retire_thread(void *arch_id);
void *_thread_stack_alloc(size_t, size_t);
@@ -716,7 +720,7 @@ void _thread_dump_info(void);
void _thread_init(void);
void _thread_sig_wrapper(int sig, siginfo_t *info, ucontext_t *context);
void _thread_printf(int fd, const char *, ...);
-void _thread_start(void);
+void _thread_start(pthread_t);
void _thread_seterrno(pthread_t, int);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
diff --git a/lib/libthr/thread/thr_resume_np.c b/lib/libthr/thread/thr_resume_np.c
index 783c45f..4d499fd 100644
--- a/lib/libthr/thread/thr_resume_np.c
+++ b/lib/libthr/thread/thr_resume_np.c
@@ -48,9 +48,6 @@ _pthread_resume_np(pthread_t thread)
/* Find the thread in the list of active threads: */
if ((ret = _find_thread(thread)) == 0) {
- pthread_t curthread;
-
- curthread = _get_curthread();
GIANT_LOCK(curthread);
if ((thread->flags & PTHREAD_FLAGS_SUSPENDED) != 0)
@@ -64,7 +61,6 @@ _pthread_resume_np(pthread_t thread)
void
_pthread_resume_all_np(void)
{
- struct pthread *curthread = _get_curthread();
struct pthread *thread;
GIANT_LOCK(curthread);
diff --git a/lib/libthr/thread/thr_self.c b/lib/libthr/thread/thr_self.c
index d213e5e..0d69538 100644
--- a/lib/libthr/thread/thr_self.c
+++ b/lib/libthr/thread/thr_self.c
@@ -40,5 +40,5 @@ pthread_t
_pthread_self(void)
{
/* Return the running thread pointer: */
- return (_get_curthread());
+ return (curthread);
}
diff --git a/lib/libthr/thread/thr_sem.c b/lib/libthr/thread/thr_sem.c
index 17059e3..c634034 100644
--- a/lib/libthr/thread/thr_sem.c
+++ b/lib/libthr/thread/thr_sem.c
@@ -213,12 +213,10 @@ _sem_trywait(sem_t *sem)
int
_sem_post(sem_t *sem)
{
- pthread_t curthread;
int retval;
_SEM_CHECK_VALIDITY(sem);
- curthread = _get_curthread();
/*
* sem_post() is required to be safe to call from within signal
* handlers. Thus, we must defer signals.
diff --git a/lib/libthr/thread/thr_setschedparam.c b/lib/libthr/thread/thr_setschedparam.c
index 14aa207..7746383 100644
--- a/lib/libthr/thread/thr_setschedparam.c
+++ b/lib/libthr/thread/thr_setschedparam.c
@@ -42,7 +42,6 @@ int
_pthread_setschedparam(pthread_t pthread, int policy,
const struct sched_param *param)
{
- pthread_t curthread;
int old_prio, in_readyq = 0, ret = 0;
if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR))
@@ -52,7 +51,6 @@ _pthread_setschedparam(pthread_t pthread, int policy,
(param->sched_priority > PTHREAD_MAX_PRIORITY))
return (ENOTSUP);
- curthread = _get_curthread();
/* Find the thread in the list of active threads: */
if ((ret = _find_thread(pthread)) == 0) {
GIANT_LOCK(curthread);
diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c
index 3aee706..dfd488d 100644
--- a/lib/libthr/thread/thr_sig.c
+++ b/lib/libthr/thread/thr_sig.c
@@ -116,7 +116,6 @@ void
_thread_sig_wrapper(int sig, siginfo_t *info, ucontext_t *context)
{
struct pthread_state_data psd;
- struct pthread *curthread = _get_curthread();
__siginfohandler_t *handler;
GIANT_LOCK(curthread);
diff --git a/lib/libthr/thread/thr_spec.c b/lib/libthr/thread/thr_spec.c
index 07ef387..eefae51 100644
--- a/lib/libthr/thread/thr_spec.c
+++ b/lib/libthr/thread/thr_spec.c
@@ -102,7 +102,6 @@ _pthread_key_delete(pthread_key_t key)
void
_thread_cleanupspecific(void)
{
- struct pthread *curthread = _get_curthread();
void *data = NULL;
int key;
int itr;
@@ -165,11 +164,8 @@ pthread_key_allocate_data(void)
int
_pthread_setspecific(pthread_key_t key, const void *value)
{
- struct pthread *pthread;
int ret = 0;
-
- /* Point to the running thread: */
- pthread = _get_curthread();
+ pthread_t pthread = curthread;
if ((pthread->specific) ||
(pthread->specific = pthread_key_allocate_data())) {
@@ -198,12 +194,9 @@ _pthread_setspecific(pthread_key_t key, const void *value)
void *
_pthread_getspecific(pthread_key_t key)
{
- struct pthread *pthread;
+ pthread_t pthread = curthread;
void *data;
- /* Point to the running thread: */
- pthread = _get_curthread();
-
/* Check if there is specific data: */
if (pthread->specific != NULL && key < PTHREAD_KEYS_MAX) {
/* Check if this key has been used before: */
diff --git a/lib/libthr/thread/thr_spinlock.c b/lib/libthr/thread/thr_spinlock.c
index 20b33f2..259977a 100644
--- a/lib/libthr/thread/thr_spinlock.c
+++ b/lib/libthr/thread/thr_spinlock.c
@@ -47,8 +47,6 @@
void
_spinunlock(spinlock_t *lck)
{
- struct pthread *curthread = _get_curthread();
-
if (umtx_unlock((struct umtx *)lck, curthread->thr_id))
abort();
}
@@ -62,8 +60,6 @@ _spinunlock(spinlock_t *lck)
void
_spinlock(spinlock_t *lck)
{
- struct pthread *curthread = _get_curthread();
-
if (umtx_lock((struct umtx *)lck, curthread->thr_id))
abort();
}
@@ -81,8 +77,6 @@ _spinlock(spinlock_t *lck)
void
_spinlock_debug(spinlock_t *lck, char *fname, int lineno)
{
- struct pthread *curthread = _get_curthread();
-
if (umtx_lock((struct umtx *)lck, curthread->thr_id))
abort();
}
OpenPOWER on IntegriCloud