From a032a6587011cbdac8c2f7e11f15dc4e592bbb55 Mon Sep 17 00:00:00 2001 From: Austin Foxley Date: Tue, 16 Feb 2010 12:27:18 -0800 Subject: mass sync with glibc nptl Signed-off-by: Austin Foxley --- libpthread/nptl/pthread_setschedparam.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'libpthread/nptl/pthread_setschedparam.c') diff --git a/libpthread/nptl/pthread_setschedparam.c b/libpthread/nptl/pthread_setschedparam.c index 55dfefc52..9b33b3e3f 100644 --- a/libpthread/nptl/pthread_setschedparam.c +++ b/libpthread/nptl/pthread_setschedparam.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -26,9 +26,9 @@ int __pthread_setschedparam ( - pthread_t threadid, - int policy, - const struct sched_param *param) + pthread_t threadid, + int policy, + const struct sched_param *param) { struct pthread *pd = (struct pthread *) threadid; @@ -39,10 +39,23 @@ __pthread_setschedparam ( int result = 0; - lll_lock (pd->lock); + lll_lock (pd->lock, LLL_PRIVATE); + + struct sched_param p; + const struct sched_param *orig_param = param; + + /* If the thread should have higher priority because of some + PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */ + if (__builtin_expect (pd->tpp != NULL, 0) + && pd->tpp->priomax > param->sched_priority) + { + p = *param; + p.sched_priority = pd->tpp->priomax; + param = &p; + } /* Try to set the scheduler information. */ - if (__builtin_expect (sched_setscheduler (pd->tid, policy, + if (__builtin_expect (__sched_setscheduler (pd->tid, policy, param) == -1, 0)) result = errno; else @@ -50,11 +63,11 @@ __pthread_setschedparam ( /* We succeeded changing the kernel information. Reflect this change in the thread descriptor. */ pd->schedpolicy = policy; - memcpy (&pd->schedparam, param, sizeof (struct sched_param)); + memcpy (&pd->schedparam, orig_param, sizeof (struct sched_param)); pd->flags |= ATTR_FLAG_SCHED_SET | ATTR_FLAG_POLICY_SET; } - lll_unlock (pd->lock); + lll_unlock (pd->lock, LLL_PRIVATE); return result; } -- cgit v1.2.3