if passed thread pointer is equal to current thread, pass -1 to kernel

to speed up searching.
This commit is contained in:
David Xu 2008-03-19 06:38:21 +00:00
parent 45aea8de6e
commit 86a06c6000
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=177370

View File

@ -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);