diff options
author | 2011-12-28 04:59:31 +0000 | |
---|---|---|
committer | 2011-12-28 04:59:31 +0000 | |
commit | 1bbb51b7c7b26224d8ceef9e36ec869b4343a38f (patch) | |
tree | 7d68c44d9d21a8e168f82264b923916c422d221c | |
parent | These utilities were already part of 1BSD, and some authors are known. (diff) | |
download | wireguard-openbsd-1bbb51b7c7b26224d8ceef9e36ec869b4343a38f.tar.xz wireguard-openbsd-1bbb51b7c7b26224d8ceef9e36ec869b4343a38f.zip |
pthread_self() may be much cheaper and never more expensive than getthrid()
so prefer it for identifying the current thread
-rw-r--r-- | lib/librthread/rthread.c | 5 | ||||
-rw-r--r-- | lib/librthread/rthread_np.c | 4 | ||||
-rw-r--r-- | lib/librthread/rthread_sched.c | 14 |
3 files changed, 12 insertions, 11 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 313dddcd513..b4016f656d5 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.48 2011/12/27 17:33:21 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.49 2011/12/28 04:59:31 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -277,10 +277,11 @@ int pthread_join(pthread_t thread, void **retval) { int e; + pthread_t self = pthread_self(); if (thread == NULL) e = EINVAL; - else if (thread->tid == getthrid()) + else if (thread == self) e = EDEADLK; else if (thread->flags & THREAD_DETACHED) e = EINVAL; diff --git a/lib/librthread/rthread_np.c b/lib/librthread/rthread_np.c index cb36095a917..69acbd458e6 100644 --- a/lib/librthread/rthread_np.c +++ b/lib/librthread/rthread_np.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_np.c,v 1.5 2007/07/08 01:53:46 kurt Exp $ */ +/* $OpenBSD: rthread_np.c,v 1.6 2011/12/28 04:59:31 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org> @@ -44,7 +44,7 @@ pthread_set_name_np(pthread_t thread, const char *name) int pthread_main_np(void) { - return (!_threads_ready || getthrid() == _initial_thread.tid ? 1 : 0); + return (!_threads_ready || pthread_self() == &_initial_thread ? 1 : 0); } diff --git a/lib/librthread/rthread_sched.c b/lib/librthread/rthread_sched.c index c11c369ae2a..25e4b4c804e 100644 --- a/lib/librthread/rthread_sched.c +++ b/lib/librthread/rthread_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sched.c,v 1.8 2011/11/06 11:48:59 guenther Exp $ */ +/* $OpenBSD: rthread_sched.c,v 1.9 2011/12/28 04:59:31 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -123,13 +123,13 @@ pthread_suspend_np(pthread_t thread) { int errn = 0; - if (thread->tid == getthrid()) + if (thread == pthread_self()) return (EDEADLK); /* * XXX Avoid a bug in current signal handling by refusing to * suspend the main thread. */ - if (thread->tid != _initial_thread.tid) + if (thread != &_initial_thread) if (kill(thread->tid, SIGSTOP) == -1) errn = errno; return (errn); @@ -139,11 +139,11 @@ void pthread_suspend_all_np(void) { pthread_t t; - pid_t me = getthrid(); + pthread_t self = pthread_self(); _spinlock(&_thread_lock); LIST_FOREACH(t, &_thread_list, threads) - if (t->tid != me) + if (t != self) pthread_suspend_np(t); _spinunlock(&_thread_lock); } @@ -163,11 +163,11 @@ void pthread_resume_all_np(void) { pthread_t t; - pid_t me = getthrid(); + pthread_t self = pthread_self(); _spinlock(&_thread_lock); LIST_FOREACH(t, &_thread_list, threads) - if (t->tid != me) + if (t != self) pthread_resume_np(t); _spinunlock(&_thread_lock); } |