diff options
| author | ad <ad@NetBSD.org> | 2008-06-28 10:29:37 +0000 |
|---|---|---|
| committer | ad <ad@NetBSD.org> | 2008-06-28 10:29:37 +0000 |
| commit | cbd43ffa55c43f368f793c80465bfcbe883b5dc7 (patch) | |
| tree | 3475b48477d2226956925e025938382b7b57f2af /lib/libpthread | |
| parent | e645b45bcf30a080ba6aa204346c51b0269f8760 (diff) | |
Now that we have all the scheduling gunk, make these do something useful:
pthread_attr_get_np
pthread_attr_setschedparam
pthread_attr_getschedparam
pthread_attr_setschedpolicy
pthread_attr_getschedpolicy
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread.c | 30 | ||||
| -rw-r--r-- | lib/libpthread/pthread_attr.c | 71 | ||||
| -rw-r--r-- | lib/libpthread/pthread_int.h | 5 |
3 files changed, 74 insertions, 32 deletions
diff --git a/lib/libpthread/pthread.c b/lib/libpthread/pthread.c index 365b7f32b0a..73bb194b169 100644 --- a/lib/libpthread/pthread.c +++ b/lib/libpthread/pthread.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread.c,v 1.102 2008/06/25 11:06:34 ad Exp $ */ +/* $NetBSD: pthread.c,v 1.103 2008/06/28 10:29:37 ad Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread.c,v 1.102 2008/06/25 11:06:34 ad Exp $"); +__RCSID("$NetBSD: pthread.c,v 1.103 2008/06/28 10:29:37 ad Exp $"); #define __EXPOSE_STACK 1 @@ -415,7 +415,8 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, newthread, startfunc, arg); flag = LWP_DETACHED; - if ((newthread->pt_flags & PT_FLAG_SUSPENDED) != 0) + if ((newthread->pt_flags & PT_FLAG_SUSPENDED) != 0 || + (attr->pta_flags & PT_FLAG_EXPLICIT_SCHED) != 0) flag |= LWP_SUSPENDED; ret = _lwp_create(&newthread->pt_uc, flag, &newthread->pt_lid); if (ret != 0) { @@ -427,6 +428,16 @@ pthread_create(pthread_t *thread, const pthread_attr_t *attr, return ret; } + if ((attr->pta_flags & PT_FLAG_EXPLICIT_SCHED) != 0) { + if (p != NULL) { + (void)pthread_setschedparam(newthread, p->ptap_policy, + &p->ptap_sp); + } + if ((newthread->pt_flags & PT_FLAG_SUSPENDED) == 0) { + (void)_lwp_continue(newthread->pt_lid); + } + } + *thread = newthread; return 0; @@ -1291,3 +1302,16 @@ pthread__hashlock(volatile const void *p) v = (uintptr_t)p; return &hashlocks[((v >> 9) ^ (v >> 3)) & (NHASHLOCK - 1)].mutex; } + +int +pthread__checkpri(int pri) +{ + static int havepri, min, max; + + if (!havepri) { + min = sysconf(_SC_SCHED_PRI_MIN); + max = sysconf(_SC_SCHED_PRI_MAX); + havepri = 1; + } + return (pri < min || pri > max) ? EINVAL : 0; +} diff --git a/lib/libpthread/pthread_attr.c b/lib/libpthread/pthread_attr.c index d1316508e70..20c5ff7ab0e 100644 --- a/lib/libpthread/pthread_attr.c +++ b/lib/libpthread/pthread_attr.c @@ -1,7 +1,7 @@ -/* $NetBSD: pthread_attr.c,v 1.9 2008/06/25 11:07:07 ad Exp $ */ +/* $NetBSD: pthread_attr.c,v 1.10 2008/06/28 10:29:37 ad Exp $ */ /*- - * Copyright (c) 2001,2002,2003 The NetBSD Foundation, Inc. + * Copyright (c) 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_attr.c,v 1.9 2008/06/25 11:07:07 ad Exp $"); +__RCSID("$NetBSD: pthread_attr.c,v 1.10 2008/06/28 10:29:37 ad Exp $"); #include <errno.h> #include <stdio.h> @@ -56,6 +56,7 @@ pthread__attr_init_private(pthread_attr_t *attr) if (p != NULL) { memset(p, 0, sizeof(*p)); attr->pta_private = p; + p->ptap_policy = SCHED_OTHER; } return p; } @@ -101,8 +102,7 @@ pthread_attr_get_np(pthread_t thread, pthread_attr_t *attr) p->ptap_stackaddr = thread->pt_stack.ss_sp; p->ptap_stacksize = thread->pt_stack.ss_size; p->ptap_guardsize = (size_t)sysconf(_SC_PAGESIZE); - - return 0; + return pthread_getschedparam(thread, &p->ptap_policy, &p->ptap_sp); } @@ -232,57 +232,72 @@ pthread_attr_setscope(pthread_attr_t *attr, int scope) int -/*ARGSUSED*/ pthread_attr_setschedparam(pthread_attr_t *attr, - const struct sched_param *param) + const struct sched_param *param) { + struct pthread_attr_private *p; + int error; if (param == NULL) return EINVAL; - - if (param->sched_priority != 0) - return EINVAL; - - return 0; + p = pthread__attr_init_private(attr); + if (p == NULL) + return ENOMEM; + error = pthread__checkpri(param->sched_priority); + if (error == 0) + p->ptap_sp = *param; + return error; } int -/*ARGSUSED*/ pthread_attr_getschedparam(const pthread_attr_t *attr, - struct sched_param *param) + struct sched_param *param) { + struct pthread_attr_private *p; if (param == NULL) return EINVAL; - - param->sched_priority = 0; - + p = attr->pta_private; + if (p == NULL) + return ENOMEM; + *param = p->ptap_sp; return 0; } int -/*ARGSUSED*/ -pthread_attr_setschedpolicy(pthread_attr_t *attr, - int policy) +pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) { + struct pthread_attr_private *p; - if (policy != SCHED_OTHER) - return ENOTSUP; - return 0; + switch (policy) { + case SCHED_OTHER: + case SCHED_FIFO: + case SCHED_RR: + p = pthread__attr_init_private(attr); + if (p == NULL) + return ENOMEM; + p->ptap_policy = policy; + return 0; + default: + return ENOTSUP; + } } int -/*ARGSUSED*/ -pthread_attr_getschedpolicy(const pthread_attr_t *attr, - int *policy) +pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) { + struct pthread_attr_private *p; - *policy = SCHED_OTHER; - + p = attr->pta_private; + if (p == NULL) { + *policy = SCHED_OTHER; + return 0; + } + *policy = p->ptap_policy; return 0; } diff --git a/lib/libpthread/pthread_int.h b/lib/libpthread/pthread_int.h index bd43a6930f7..4770752890b 100644 --- a/lib/libpthread/pthread_int.h +++ b/lib/libpthread/pthread_int.h @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_int.h,v 1.69 2008/05/25 17:05:28 ad Exp $ */ +/* $NetBSD: pthread_int.h,v 1.70 2008/06/28 10:29:37 ad Exp $ */ /*- * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -79,6 +79,8 @@ struct pthread_attr_private { void *ptap_stackaddr; size_t ptap_stacksize; size_t ptap_guardsize; + struct sched_param ptap_sp; + int ptap_policy; }; struct pthread_lock_ops { @@ -288,6 +290,7 @@ void pthread__errorfunc(const char *, int, const char *, const char *) char *pthread__getenv(const char *) PTHREAD_HIDE; void pthread__cancelled(void) PTHREAD_HIDE; void pthread__mutex_deferwake(pthread_t, pthread_mutex_t *) PTHREAD_HIDE; +int pthread__checkpri(int) PTHREAD_HIDE; #ifndef pthread__smt_pause #define pthread__smt_pause() /* nothing */ |
