summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_create.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2006-07-12 06:13:18 +0000
committerdavidxu <davidxu@FreeBSD.org>2006-07-12 06:13:18 +0000
commitecacf536b0f70b9b9579910c7d6dd8b5a9608136 (patch)
treef3ebabe7f0c598fbcd24fc997f7310e276d3efb0 /lib/libthr/thread/thr_create.c
parent3117fa3da4d89744ddfe45c3ac759ab430bd2950 (diff)
downloadFreeBSD-src-ecacf536b0f70b9b9579910c7d6dd8b5a9608136.zip
FreeBSD-src-ecacf536b0f70b9b9579910c7d6dd8b5a9608136.tar.gz
Use kernel facilities to support real-time scheduling.
Diffstat (limited to 'lib/libthr/thread/thr_create.c')
-rw-r--r--lib/libthr/thread/thr_create.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c
index bb5724a..e74278d 100644
--- a/lib/libthr/thread/thr_create.c
+++ b/lib/libthr/thread/thr_create.c
@@ -50,6 +50,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
{
struct pthread *curthread, *new_thread;
struct thr_param param;
+ struct thr_sched_param sched_param;
int ret = 0, locked, create_suspended;
sigset_t set, oset;
@@ -105,30 +106,6 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
new_thread->arg = arg;
new_thread->cancelflags = PTHREAD_CANCEL_ENABLE |
PTHREAD_CANCEL_DEFERRED;
- /*
- * Check if this thread is to inherit the scheduling
- * attributes from its parent:
- */
- if (new_thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED) {
- /*
- * Copy the scheduling attributes. Lock the scheduling
- * lock to get consistent scheduling parameters.
- */
- THR_LOCK(curthread);
- new_thread->base_priority = curthread->base_priority;
- new_thread->attr.prio = curthread->base_priority;
- new_thread->attr.sched_policy = curthread->attr.sched_policy;
- THR_UNLOCK(curthread);
- } else {
- /*
- * Use just the thread priority, leaving the
- * other scheduling attributes as their
- * default values:
- */
- new_thread->base_priority = new_thread->attr.prio;
- }
- new_thread->active_priority = new_thread->base_priority;
-
/* Initialize the mutex queue: */
TAILQ_INIT(&new_thread->mutexq);
@@ -166,6 +143,13 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
param.flags = 0;
if (new_thread->attr.flags & PTHREAD_SCOPE_SYSTEM)
param.flags |= THR_SYSTEM_SCOPE;
+ if (new_thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED)
+ param.sched = NULL;
+ else {
+ param.sched = &sched_param;
+ sched_param.policy = new_thread->attr.sched_policy;
+ sched_param.param.sched_priority = new_thread->attr.prio;
+ }
/* Schedule the new thread. */
if (create_suspended) {
@@ -177,6 +161,15 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
ret = thr_new(&param, sizeof(param));
+ if (ret != 0) {
+ ret = errno;
+ /*
+ * Translate EPROCLIM into well-known POSIX code EAGAIN.
+ */
+ if (ret == EPROCLIM)
+ ret = EAGAIN;
+ }
+
if (create_suspended)
__sys_sigprocmask(SIG_SETMASK, &oset, NULL);
@@ -196,7 +189,6 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
_thr_ref_delete_unlocked(curthread, new_thread);
THREAD_LIST_UNLOCK(curthread);
(*thread) = 0;
- ret = EAGAIN;
} else if (locked) {
_thr_report_creation(curthread, new_thread);
THR_THREAD_UNLOCK(curthread, new_thread);
OpenPOWER on IntegriCloud