From b33c17d37d7e40941775515d05953afa434bec48 Mon Sep 17 00:00:00 2001 From: guenther Date: Wed, 29 Apr 2015 06:01:37 +0000 Subject: [PATCH] Delete the duplicated sched_{policy,param} members from the internal struct pthread and instead use the values from the embedded struct pthread_attr. For bonus points, pay attention to the sched_inherit attribute and possibly set the values from the parent thread. Problem noted by natano of bitrig. --- lib/librthread/rthread.c | 9 ++++++++- lib/librthread/rthread.h | 4 +--- lib/librthread/rthread_sched.c | 20 +++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 688f438a27b..72babbf5032 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.80 2015/04/07 01:27:07 guenther Exp $ */ +/* $OpenBSD: rthread.c,v 1.81 2015/04/29 06:01:37 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst * All Rights Reserved. @@ -197,6 +197,7 @@ _rthread_init(void) _thread_pagesize = (size_t)sysconf(_SC_PAGESIZE); _rthread_attr_default.guard_size = _thread_pagesize; + thread->attr = _rthread_attr_default; _rthread_initlib(); @@ -429,6 +430,12 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, thread->tid = -1; thread->attr = attr != NULL ? *(*attr) : _rthread_attr_default; + if (thread->attr.sched_inherit == PTHREAD_INHERIT_SCHED) { + pthread_t self = pthread_self(); + + thread->attr.sched_policy = self->attr.sched_policy; + thread->attr.sched_param = self->attr.sched_param; + } if (thread->attr.detach_state == PTHREAD_CREATE_DETACHED) thread->flags |= THREAD_DETACHED; thread->flags |= THREAD_CANCEL_ENABLE|THREAD_CANCEL_DEFERRED; diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h index a777ad8c607..9e087a90595 100644 --- a/lib/librthread/rthread.h +++ b/lib/librthread/rthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.h,v 1.50 2014/08/31 04:02:08 guenther Exp $ */ +/* $OpenBSD: rthread.h,v 1.51 2015/04/29 06:01:37 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst * All Rights Reserved. @@ -170,9 +170,7 @@ struct pthread { LIST_ENTRY(pthread) threads; TAILQ_ENTRY(pthread) waiting; pthread_cond_t blocking_cond; - int sched_policy; struct pthread_attr attr; - struct sched_param sched_param; struct rthread_storage *local_storage; struct rthread_cleanup_fn *cleanup_fns; int myerrno; diff --git a/lib/librthread/rthread_sched.c b/lib/librthread/rthread_sched.c index 2a63e5d3633..1df1ed19943 100644 --- a/lib/librthread/rthread_sched.c +++ b/lib/librthread/rthread_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sched.c,v 1.12 2012/03/22 15:26:04 kurt Exp $ */ +/* $OpenBSD: rthread_sched.c,v 1.13 2015/04/29 06:01:37 guenther Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst * All Rights Reserved. @@ -32,9 +32,9 @@ int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param) { - *policy = thread->sched_policy; + *policy = thread->attr.sched_policy; if (param) - *param = thread->sched_param; + *param = thread->attr.sched_param; return (0); } @@ -47,15 +47,16 @@ pthread_setschedparam(pthread_t thread, int policy, if (policy != SCHED_OTHER && policy != SCHED_FIFO && policy != SCHED_RR) return (EINVAL); - thread->sched_policy = policy; + thread->attr.sched_policy = policy; if (param) - thread->sched_param = *param; + thread->attr.sched_param = *param; return (0); } int -pthread_attr_getschedparam(const pthread_attr_t *attrp, struct sched_param *param) +pthread_attr_getschedparam(const pthread_attr_t *attrp, + struct sched_param *param) { *param = (*attrp)->sched_param; @@ -63,7 +64,8 @@ pthread_attr_getschedparam(const pthread_attr_t *attrp, struct sched_param *para } int -pthread_attr_setschedparam(pthread_attr_t *attrp, const struct sched_param *param) +pthread_attr_setschedparam(pthread_attr_t *attrp, + const struct sched_param *param) { (*attrp)->sched_param = *param; @@ -112,13 +114,13 @@ pthread_attr_setinheritsched(pthread_attr_t *attrp, int inherit) int pthread_getprio(pthread_t thread) { - return (thread->sched_param.sched_priority); + return (thread->attr.sched_param.sched_priority); } int pthread_setprio(pthread_t thread, int priority) { - thread->sched_param.sched_priority = priority; + thread->attr.sched_param.sched_priority = priority; return (0); } -- 2.20.1