summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2008-03-19 06:38:21 +0000
committerdavidxu <davidxu@FreeBSD.org>2008-03-19 06:38:21 +0000
commite846a1612b584a4d896189eb9ece9b3fa61d3878 (patch)
tree08e14392e1b8cc6902848a938ef04443b6afe7ee /lib/libthr
parent4350e599a35ac10933477fef816e346753c80a2a (diff)
downloadFreeBSD-src-e846a1612b584a4d896189eb9ece9b3fa61d3878.zip
FreeBSD-src-e846a1612b584a4d896189eb9ece9b3fa61d3878.tar.gz
if passed thread pointer is equal to current thread, pass -1 to kernel
to speed up searching.
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_affinity.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/libthr/thread/thr_affinity.c b/lib/libthr/thread/thr_affinity.c
index 240dd74..a300bb7 100644
--- a/lib/libthr/thread/thr_affinity.c
+++ b/lib/libthr/thread/thr_affinity.c
@@ -45,29 +45,37 @@ _pthread_setaffinity_np(pthread_t td, size_t cpusetsize, const cpuset_t *cpuset)
lwpid_t tid;
int error;
- THR_THREAD_LOCK(curthread, td);
- if (td->state == PS_DEAD) {
+ if (td == curthread) {
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ -1, cpusetsize, cpuset);
+ if (error == -1)
+ error = errno;
+ } else {
+ THR_THREAD_LOCK(curthread, td);
+ if (td->state == PS_DEAD) {
+ THR_THREAD_UNLOCK(curthread, td);
+ return (EINVAL);
+ }
+ tid = TID(td);
+ error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, tid,
+ cpusetsize, cpuset);
+ if (error == -1)
+ error = errno;
THR_THREAD_UNLOCK(curthread, td);
- return (EINVAL);
}
- tid = TID(td);
- error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, tid,
- cpusetsize, cpuset);
- if (error == -1)
- error = errno;
- THR_THREAD_UNLOCK(curthread, td);
return (error);
}
int
_pthread_getaffinity_np(pthread_t td, size_t cpusetsize, cpuset_t *cpuset)
{
+ struct pthread *curthread = _get_curthread();
lwpid_t tid;
int error;
tid = TID(td);
- error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, tid,
- cpusetsize, cpuset);
+ error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ (td == curthread) ? -1 : tid, cpusetsize, cpuset);
if (error == -1)
error = errno;
return (error);
OpenPOWER on IntegriCloud