diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-07-12 06:13:18 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-07-12 06:13:18 +0000 |
commit | ecacf536b0f70b9b9579910c7d6dd8b5a9608136 (patch) | |
tree | f3ebabe7f0c598fbcd24fc997f7310e276d3efb0 /lib/libthr/thread/thr_setprio.c | |
parent | 3117fa3da4d89744ddfe45c3ac759ab430bd2950 (diff) | |
download | FreeBSD-src-ecacf536b0f70b9b9579910c7d6dd8b5a9608136.zip FreeBSD-src-ecacf536b0f70b9b9579910c7d6dd8b5a9608136.tar.gz |
Use kernel facilities to support real-time scheduling.
Diffstat (limited to 'lib/libthr/thread/thr_setprio.c')
-rw-r--r-- | lib/libthr/thread/thr_setprio.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/libthr/thread/thr_setprio.c b/lib/libthr/thread/thr_setprio.c index bb9a9bf..51a283e 100644 --- a/lib/libthr/thread/thr_setprio.c +++ b/lib/libthr/thread/thr_setprio.c @@ -43,14 +43,29 @@ __weak_reference(_pthread_setprio, pthread_setprio); int _pthread_setprio(pthread_t pthread, int prio) { - int ret, policy; - struct sched_param param; + struct pthread *curthread = _get_curthread(); + struct sched_param param; + int ret; - if ((ret = _pthread_getschedparam(pthread, &policy, ¶m)) == 0) { - param.sched_priority = prio; - ret = _pthread_setschedparam(pthread, policy, ¶m); + param.sched_priority = prio; + if (pthread == curthread) { + THR_LOCK(curthread); + ret = sched_setparam((pid_t)curthread->tid, ¶m); + 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 = sched_setparam((pid_t)pthread->tid, ¶m); + if (ret == -1) + ret = errno; + else + pthread->attr.prio = prio; + THR_THREAD_UNLOCK(curthread, pthread); + _thr_ref_delete(curthread, pthread); } - - /* Return the error status: */ return (ret); } |