thr_mutex_protocol.c revision 174112
1285206Sdes/*
2255581Sdes * Copyright (c) 1998 Daniel Eischen <eischen@vigrid.com>.
3255581Sdes * All rights reserved.
4255581Sdes *
5255581Sdes * Redistribution and use in source and binary forms, with or without
6255581Sdes * modification, are permitted provided that the following conditions
7255581Sdes * are met:
8255581Sdes * 1. Redistributions of source code must retain the above copyright
9255581Sdes *    notice, this list of conditions and the following disclaimer.
10255581Sdes * 2. Redistributions in binary form must reproduce the above copyright
11255581Sdes *    notice, this list of conditions and the following disclaimer in the
12255581Sdes *    documentation and/or other materials provided with the distribution.
13255581Sdes * 3. All advertising materials mentioning features or use of this software
14255581Sdes *    must display the following acknowledgement:
15255581Sdes *	This product includes software developed by Daniel Eischen.
16255581Sdes * 4. Neither the name of the author nor the names of any co-contributors
17255581Sdes *    may be used to endorse or promote products derived from this software
18255581Sdes *    without specific prior written permission.
19255581Sdes *
20255581Sdes * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' AND
21255581Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22255581Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23255581Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24255581Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25285206Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26255581Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27255581Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28255581Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29255581Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30255581Sdes * SUCH DAMAGE.
31255581Sdes *
32255581Sdes * $FreeBSD: head/lib/libkse/thread/thr_mutex_protocol.c 174112 2007-11-30 17:20:29Z deischen $
33255581Sdes */
34255581Sdes
35255581Sdes#include "namespace.h"
36255581Sdes#include <string.h>
37255581Sdes#include <stdlib.h>
38255581Sdes#include <errno.h>
39255581Sdes#include <pthread.h>
40255581Sdes#include "un-namespace.h"
41255581Sdes#include "thr_private.h"
42255581Sdes
43255581SdesLT10_COMPAT_PRIVATE(_pthread_mutexattr_getprotocol);
44255581SdesLT10_COMPAT_DEFAULT(pthread_mutexattr_getprotocol);
45285206SdesLT10_COMPAT_PRIVATE(_pthread_mutexattr_setprotocol);
46255581SdesLT10_COMPAT_DEFAULT(pthread_mutexattr_setprotocol);
47255581Sdes
48255581Sdes__weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol);
49255581Sdes__weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
50255581Sdes
51255581Sdesint
52255581Sdes_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
53255581Sdes{
54255581Sdes	int ret = 0;
55255581Sdes
56255581Sdes	if ((mattr == NULL) || (*mattr == NULL))
57255581Sdes		ret = EINVAL;
58255581Sdes	else
59255581Sdes		*protocol = (*mattr)->m_protocol;
60255581Sdes
61255581Sdes	return(ret);
62255581Sdes}
63255581Sdes
64255581Sdesint
65255581Sdes_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
66255581Sdes{
67255581Sdes	int ret = 0;
68255581Sdes
69255581Sdes	if ((mattr == NULL) || (*mattr == NULL) ||
70255581Sdes	    (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
71255581Sdes		ret = EINVAL;
72255581Sdes	else {
73255581Sdes		(*mattr)->m_protocol = protocol;
74255581Sdes		(*mattr)->m_ceiling = THR_MAX_PRIORITY;
75255581Sdes	}
76255581Sdes	return(ret);
77285206Sdes}
78285206Sdes
79285206Sdes