thr_getschedparam.c revision 174112
119370Spst/* 219370Spst * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>. 319370Spst * All rights reserved. 419370Spst * 519370Spst * Redistribution and use in source and binary forms, with or without 619370Spst * modification, are permitted provided that the following conditions 719370Spst * are met: 819370Spst * 1. Redistributions of source code must retain the above copyright 919370Spst * notice, this list of conditions and the following disclaimer. 1019370Spst * 2. Redistributions in binary form must reproduce the above copyright 1119370Spst * notice, this list of conditions and the following disclaimer in the 1219370Spst * documentation and/or other materials provided with the distribution. 1319370Spst * 3. All advertising materials mentioning features or use of this software 1419370Spst * must display the following acknowledgement: 1519370Spst * This product includes software developed by Daniel Eischen. 1619370Spst * 4. Neither the name of the author nor the names of any co-contributors 1719370Spst * may be used to endorse or promote products derived from this software 1819370Spst * without specific prior written permission. 1919370Spst * 2019370Spst * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND 2119370Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2219370Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2319370Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2419370Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2519370Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2619370Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2719370Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2819370Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2919370Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3019370Spst * SUCH DAMAGE. 3119370Spst * 3219370Spst * $FreeBSD: head/lib/libkse/thread/thr_getschedparam.c 174112 2007-11-30 17:20:29Z deischen $ 3319370Spst */ 3419370Spst 3519370Spst#include "namespace.h" 3619370Spst#include <errno.h> 3719370Spst#include <pthread.h> 3819370Spst#include "un-namespace.h" 3919370Spst#include "thr_private.h" 4019370Spst 4119370SpstLT10_COMPAT_PRIVATE(_pthread_getschedparam); 4219370SpstLT10_COMPAT_DEFAULT(pthread_getschedparam); 4319370Spst 4419370Spst__weak_reference(_pthread_getschedparam, pthread_getschedparam); 4519370Spst 4619370Spstint 4719370Spst_pthread_getschedparam(pthread_t pthread, int *policy, 4819370Spst struct sched_param *param) 4919370Spst{ 5019370Spst struct pthread *curthread = _get_curthread(); 5119370Spst int ret, tmp; 52 53 if ((param == NULL) || (policy == NULL)) 54 /* Return an invalid argument error: */ 55 ret = EINVAL; 56 else if (pthread == curthread) { 57 /* 58 * Avoid searching the thread list when it is the current 59 * thread. 60 */ 61 THR_SCHED_LOCK(curthread, curthread); 62 param->sched_priority = 63 THR_BASE_PRIORITY(pthread->base_priority); 64 tmp = pthread->attr.sched_policy; 65 THR_SCHED_UNLOCK(curthread, curthread); 66 *policy = tmp; 67 ret = 0; 68 } 69 /* Find the thread in the list of active threads. */ 70 else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) 71 == 0) { 72 THR_SCHED_LOCK(curthread, pthread); 73 param->sched_priority = 74 THR_BASE_PRIORITY(pthread->base_priority); 75 tmp = pthread->attr.sched_policy; 76 THR_SCHED_UNLOCK(curthread, pthread); 77 _thr_ref_delete(curthread, pthread); 78 *policy = tmp; 79 } 80 return (ret); 81} 82