From 2b1dbc0acb716180145708fa4f5787322ac795e2 Mon Sep 17 00:00:00 2001 From: davidxu Date: Thu, 13 Jul 2006 22:45:19 +0000 Subject: Caching scheduling policy and priority in userland, a critical but baddly written application is frequently changing thread priority for SCHED_OTHER policy. --- lib/libthr/thread/thr_setprio.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'lib/libthr/thread/thr_setprio.c') 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, ¶m, 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, + ¶m, 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, ¶m, 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, ¶m, + sizeof(param)); + if (ret == -1) + ret = errno; + else + pthread->attr.prio = prio; + } THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); } -- cgit v1.1