summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_setprio.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-07-13 22:45:19 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-07-13 22:45:19 +0000
commit2b1dbc0acb716180145708fa4f5787322ac795e2 (patch)
tree38d9ff271ff8237cbfb86fa05d16da871f8e0dd2 /lib/libthr/thread/thr_setprio.c
parent27c2ca32122c31456d60bac89aae091ff18728b0 (diff)
downloadFreeBSD-src-2b1dbc0acb716180145708fa4f5787322ac795e2.zip
FreeBSD-src-2b1dbc0acb716180145708fa4f5787322ac795e2.tar.gz
Caching scheduling policy and priority in userland, a critical but baddly
written application is frequently changing thread priority for SCHED_OTHER policy.
Diffstat (limited to 'lib/libthr/thread/thr_setprio.c')
-rw-r--r--lib/libthr/thread/thr_setprio.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/libthr/thread/thr_setprio.c b/lib/libthr/thread/thr_setprio.c
index 03ac39c..78769d1 100644
--- a/lib/libthr/thread/thr_setprio.c
+++ b/lib/libthr/thread/thr_setprio.c
@@ -50,20 +50,34 @@ _pthread_setprio(pthread_t pthread, int prio)
param.sched_priority = prio;
if (pthread == curthread) {
THR_LOCK(curthread);
- ret = thr_setschedparam(curthread->tid, &param, sizeof(param));
- if (ret == -1)
- ret = errno;
- else
+ if (curthread->attr.sched_policy == SCHED_OTHER ||
+ curthread->attr.prio == prio) {
curthread->attr.prio = prio;
+ ret = 0;
+ } else {
+ ret = thr_setschedparam(curthread->tid,
+ &param, sizeof(param));
+ if (ret == -1)
+ ret = errno;
+ else
+ curthread->attr.prio = prio;
+ }
THR_UNLOCK(curthread);
} else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
== 0) {
THR_THREAD_LOCK(curthread, pthread);
- ret = thr_setschedparam(pthread->tid, &param, sizeof(param));
- if (ret == -1)
- ret = errno;
- else
+ if (pthread->attr.sched_policy == SCHED_OTHER ||
+ pthread->attr.prio == prio) {
pthread->attr.prio = prio;
+ ret = 0;
+ } else {
+ ret = thr_setschedparam(pthread->tid, &param,
+ sizeof(param));
+ if (ret == -1)
+ ret = errno;
+ else
+ pthread->attr.prio = prio;
+ }
THR_THREAD_UNLOCK(curthread, pthread);
_thr_ref_delete(curthread, pthread);
}
OpenPOWER on IntegriCloud