diff options
author | deischen <deischen@FreeBSD.org> | 2003-04-18 05:04:16 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2003-04-18 05:04:16 +0000 |
commit | 5d56aa9cb2bdbe0a18bafbdbb6eb8cf6a46beb79 (patch) | |
tree | 46bc1e113ddc7c1ed88e4fa724039df8664c963a /lib/libkse/thread/thr_setschedparam.c | |
parent | e68f624d876da04bfb6860b450593c77d80368bd (diff) | |
download | FreeBSD-src-5d56aa9cb2bdbe0a18bafbdbb6eb8cf6a46beb79.zip FreeBSD-src-5d56aa9cb2bdbe0a18bafbdbb6eb8cf6a46beb79.tar.gz |
Revamp libpthread so that it has a chance of working in an SMP
environment. This includes support for multiple KSEs and KSEGs.
The ability to create more than 1 KSE via pthread_setconcurrency()
is in the works as well as support for PTHREAD_SCOPE_SYSTEM threads.
Those should come shortly.
There are still some known issues which davidxu and I are working
on, but it'll make it easier for us by committing what we have.
This library now passes all of the ACE tests that libc_r passes
with the exception of one. It also seems to work OK with KDE
including konqueror, kwrite, etc. I haven't been able to get
mozilla to run due to lack of java plugin, so I'd be interested
to see how it works with that.
Reviewed by: davidxu
Diffstat (limited to 'lib/libkse/thread/thr_setschedparam.c')
-rw-r--r-- | lib/libkse/thread/thr_setschedparam.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/lib/libkse/thread/thr_setschedparam.c b/lib/libkse/thread/thr_setschedparam.c index 5117a26..1be9f91 100644 --- a/lib/libkse/thread/thr_setschedparam.c +++ b/lib/libkse/thread/thr_setschedparam.c @@ -42,40 +42,55 @@ int _pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param) { - int old_prio, in_readyq = 0, ret = 0; + struct pthread *curthread = _get_curthread(); + int in_syncq; + int in_readyq = 0; + int old_prio; + int ret = 0; if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) { /* Return an invalid argument error: */ ret = EINVAL; - } else if ((param->sched_priority < PTHREAD_MIN_PRIORITY) || - (param->sched_priority > PTHREAD_MAX_PRIORITY)) { + } else if ((param->sched_priority < THR_MIN_PRIORITY) || + (param->sched_priority > THR_MAX_PRIORITY)) { /* Return an unsupported value error. */ ret = ENOTSUP; /* Find the thread in the list of active threads: */ - } else if ((ret = _find_thread(pthread)) == 0) { + } else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) + == 0) { /* - * Defer signals to protect the scheduling queues from - * access by the signal handler: + * Lock the threads scheduling queue while we change + * its priority: */ - _thread_kern_sig_defer(); + THR_SCHED_LOCK(curthread, pthread); + in_syncq = pthread->flags & THR_FLAGS_IN_SYNCQ; - if (param->sched_priority != - PTHREAD_BASE_PRIORITY(pthread->base_priority)) { + /* Set the scheduling policy: */ + pthread->attr.sched_policy = policy; + + if (param->sched_priority == + THR_BASE_PRIORITY(pthread->base_priority)) + /* + * There is nothing to do; unlock the threads + * scheduling queue. + */ + THR_SCHED_UNLOCK(curthread, pthread); + else { /* * Remove the thread from its current priority * queue before any adjustments are made to its * active priority: */ old_prio = pthread->active_priority; - if ((pthread->flags & PTHREAD_FLAGS_IN_PRIOQ) != 0) { + if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0) { in_readyq = 1; - PTHREAD_PRIOQ_REMOVE(pthread); + THR_RUNQ_REMOVE(pthread); } /* Set the thread base priority: */ pthread->base_priority &= - (PTHREAD_SIGNAL_PRIORITY | PTHREAD_RT_PRIORITY); + (THR_SIGNAL_PRIORITY | THR_RT_PRIORITY); pthread->base_priority = param->sched_priority; /* Recalculate the active priority: */ @@ -92,28 +107,23 @@ _pthread_setschedparam(pthread_t pthread, int policy, * its priority if it owns any priority * protection or inheritence mutexes. */ - PTHREAD_PRIOQ_INSERT_HEAD(pthread); + THR_RUNQ_INSERT_HEAD(pthread); } else - PTHREAD_PRIOQ_INSERT_TAIL(pthread); + THR_RUNQ_INSERT_TAIL(pthread); } + /* Unlock the threads scheduling queue: */ + THR_SCHED_UNLOCK(curthread, pthread); + /* * Check for any mutex priority adjustments. This * includes checking for a priority mutex on which * this thread is waiting. */ - _mutex_notify_priochange(pthread); + _mutex_notify_priochange(curthread, pthread, in_syncq); } - - /* Set the scheduling policy: */ - pthread->attr.sched_policy = policy; - - /* - * Undefer and handle pending signals, yielding if - * necessary: - */ - _thread_kern_sig_undefer(); + _thr_ref_delete(curthread, pthread); } - return(ret); + return (ret); } |