thr_setprio.c revision 165967
1168793Sthompsa/*
2168793Sthompsa * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
3168793Sthompsa * All rights reserved.
4168793Sthompsa *
5168793Sthompsa * Redistribution and use in source and binary forms, with or without
6168793Sthompsa * modification, are permitted provided that the following conditions
7168793Sthompsa * are met:
8168793Sthompsa * 1. Redistributions of source code must retain the above copyright
9168793Sthompsa *    notice, this list of conditions and the following disclaimer.
10168793Sthompsa * 2. Redistributions in binary form must reproduce the above copyright
11168793Sthompsa *    notice, this list of conditions and the following disclaimer in the
12168793Sthompsa *    documentation and/or other materials provided with the distribution.
13168793Sthompsa * 3. Neither the name of the author nor the names of any co-contributors
14168793Sthompsa *    may be used to endorse or promote products derived from this software
15168793Sthompsa *    without specific prior written permission.
16168793Sthompsa *
17168793Sthompsa * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
18168793Sthompsa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19168793Sthompsa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20168793Sthompsa * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21168793Sthompsa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22168793Sthompsa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23168793Sthompsa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24168793Sthompsa * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25168793Sthompsa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26168793Sthompsa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27168793Sthompsa * SUCH DAMAGE.
28168793Sthompsa *
29168793Sthompsa * $FreeBSD: head/lib/libkse/thread/thr_setprio.c 165967 2007-01-12 07:26:21Z imp $
30168793Sthompsa */
31168793Sthompsa#include <pthread.h>
32171247Sthompsa#include "thr_private.h"
33171247Sthompsa
34168793SthompsaLT10_COMPAT_PRIVATE(_pthread_setprio);
35168793SthompsaLT10_COMPAT_DEFAULT(pthread_setprio);
36168793Sthompsa
37168793Sthompsa__weak_reference(_pthread_setprio, pthread_setprio);
38168793Sthompsa
39168793Sthompsaint
40168793Sthompsa_pthread_setprio(pthread_t pthread, int prio)
41168793Sthompsa{
42168793Sthompsa	int ret, policy;
43236178Srea	struct sched_param param;
44236178Srea
45168793Sthompsa	if ((ret = pthread_getschedparam(pthread, &policy, &param)) == 0) {
46168793Sthompsa		param.sched_priority = prio;
47168793Sthompsa		ret = pthread_setschedparam(pthread, policy, &param);
48168793Sthompsa	}
49168793Sthompsa
50168793Sthompsa	/* Return the error status: */
51168793Sthompsa	return (ret);
52168793Sthompsa}
53168793Sthompsa