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/pthread_attr.c | |
| 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/pthread_attr.c')
| -rw-r--r-- | lib/libpthread/pthread_attr.c | 71 |
1 files changed, 43 insertions, 28 deletions
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; } |
