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_setschedparam.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/libthr/thread/thr_setschedparam.c') diff --git a/lib/libthr/thread/thr_setschedparam.c b/lib/libthr/thread/thr_setschedparam.c index 5e2d2bf..d766e37 100644 --- a/lib/libthr/thread/thr_setschedparam.c +++ b/lib/libthr/thread/thr_setschedparam.c @@ -55,6 +55,13 @@ _pthread_setschedparam(pthread_t pthread, int policy, if (pthread == curthread) { THR_LOCK(curthread); + if (curthread->attr.sched_policy == policy && + (policy == SCHED_OTHER || + curthread->attr.prio == param->sched_priority)) { + pthread->attr.prio = param->sched_priority; + THR_UNLOCK(curthread); + return (0); + } ret = thr_setscheduler(curthread->tid, policy, param, sizeof(param)); if (ret == -1) @@ -67,6 +74,13 @@ _pthread_setschedparam(pthread_t pthread, int policy, } else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) == 0) { THR_THREAD_LOCK(curthread, pthread); + if (pthread->attr.sched_policy == policy && + (policy == SCHED_OTHER || + pthread->attr.prio == param->sched_priority)) { + pthread->attr.prio = param->sched_priority; + THR_THREAD_UNLOCK(curthread, pthread); + return (0); + } ret = thr_setscheduler(pthread->tid, policy, param, sizeof(param)); if (ret == -1) -- cgit v1.1