1144518Sdavidxu/*
2144518Sdavidxu * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
3144518Sdavidxu * All rights reserved.
4144518Sdavidxu *
5144518Sdavidxu * Redistribution and use in source and binary forms, with or without
6144518Sdavidxu * modification, are permitted provided that the following conditions
7144518Sdavidxu * are met:
8144518Sdavidxu * 1. Redistributions of source code must retain the above copyright
9144518Sdavidxu *    notice, this list of conditions and the following disclaimer.
10144518Sdavidxu * 2. Redistributions in binary form must reproduce the above copyright
11144518Sdavidxu *    notice, this list of conditions and the following disclaimer in the
12144518Sdavidxu *    documentation and/or other materials provided with the distribution.
13144518Sdavidxu * 3. All advertising materials mentioning features or use of this software
14144518Sdavidxu *    must display the following acknowledgement:
15144518Sdavidxu *	This product includes software developed by Daniel Eischen.
16144518Sdavidxu * 4. Neither the name of the author nor the names of any co-contributors
17144518Sdavidxu *    may be used to endorse or promote products derived from this software
18144518Sdavidxu *    without specific prior written permission.
19144518Sdavidxu *
20144518Sdavidxu * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
21144518Sdavidxu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22144518Sdavidxu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23144518Sdavidxu * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24144518Sdavidxu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25144518Sdavidxu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26144518Sdavidxu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27144518Sdavidxu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28144518Sdavidxu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29144518Sdavidxu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30144518Sdavidxu * SUCH DAMAGE.
31144518Sdavidxu *
32144518Sdavidxu * $FreeBSD$
33144518Sdavidxu */
34144518Sdavidxu
35157457Sdavidxu#include "namespace.h"
36162499Sdavidxu#include <sys/types.h>
37162499Sdavidxu#include <sys/rtprio.h>
38144518Sdavidxu#include <errno.h>
39144518Sdavidxu#include <pthread.h>
40157457Sdavidxu#include "un-namespace.h"
41144518Sdavidxu
42144518Sdavidxu#include "thr_private.h"
43144518Sdavidxu
44144518Sdavidxu__weak_reference(_pthread_getschedparam, pthread_getschedparam);
45144518Sdavidxu
46144518Sdavidxuint
47144518Sdavidxu_pthread_getschedparam(pthread_t pthread, int *policy,
48144518Sdavidxu	struct sched_param *param)
49144518Sdavidxu{
50144518Sdavidxu	struct pthread *curthread = _get_curthread();
51238645Sdavidxu	int ret = 0;
52144518Sdavidxu
53160287Sdavidxu	if (policy == NULL || param == NULL)
54160287Sdavidxu		return (EINVAL);
55160287Sdavidxu
56238643Sdavidxu	/*
57238643Sdavidxu	 * Avoid searching the thread list when it is the current
58238643Sdavidxu	 * thread.
59238643Sdavidxu	 */
60238643Sdavidxu	if (pthread == curthread)
61160287Sdavidxu		THR_LOCK(curthread);
62238643Sdavidxu	else if ((ret = _thr_find_thread(curthread, pthread, /*include dead*/0)))
63238643Sdavidxu		return (ret);
64238643Sdavidxu	*policy = pthread->attr.sched_policy;
65238643Sdavidxu	param->sched_priority = pthread->attr.prio;
66238643Sdavidxu	THR_THREAD_UNLOCK(curthread, pthread);
67144518Sdavidxu	return (ret);
68144518Sdavidxu}
69