2 * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. Neither the name of the author nor the names of any co-contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 #include <sys/cdefs.h>
61 __FBSDID("$FreeBSD$");
63 #include "namespace.h"
68 #include <pthread_np.h>
69 #include "un-namespace.h"
71 #include "thr_private.h"
73 __weak_reference(_pthread_mutexattr_init, pthread_mutexattr_init);
74 __weak_reference(_pthread_mutexattr_setkind_np, pthread_mutexattr_setkind_np);
75 __weak_reference(_pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np);
76 __weak_reference(_pthread_mutexattr_gettype, pthread_mutexattr_gettype);
77 __weak_reference(_pthread_mutexattr_settype, pthread_mutexattr_settype);
78 __weak_reference(_pthread_mutexattr_destroy, pthread_mutexattr_destroy);
79 __weak_reference(_pthread_mutexattr_getpshared, pthread_mutexattr_getpshared);
80 __weak_reference(_pthread_mutexattr_setpshared, pthread_mutexattr_setpshared);
81 __weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol);
82 __weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
83 __weak_reference(_pthread_mutexattr_getprioceiling,
84 pthread_mutexattr_getprioceiling);
85 __weak_reference(_pthread_mutexattr_setprioceiling,
86 pthread_mutexattr_setprioceiling);
87 __weak_reference(_pthread_mutexattr_getrobust, pthread_mutexattr_getrobust);
88 __weak_reference(_pthread_mutexattr_setrobust, pthread_mutexattr_setrobust);
91 _pthread_mutexattr_init(pthread_mutexattr_t *attr)
94 pthread_mutexattr_t pattr;
96 if ((pattr = (pthread_mutexattr_t)
97 malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
100 memcpy(pattr, &_pthread_mutexattr_default,
101 sizeof(struct pthread_mutex_attr));
109 _pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
112 if (attr == NULL || *attr == NULL) {
116 (*attr)->m_type = kind;
123 _pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
137 _pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
141 if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) {
144 (*attr)->m_type = type;
151 _pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
155 if (attr == NULL || *attr == NULL || (*attr)->m_type >=
156 PTHREAD_MUTEX_TYPE_MAX) {
159 *type = (*attr)->m_type;
166 _pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
169 if (attr == NULL || *attr == NULL) {
180 _pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
184 if (attr == NULL || *attr == NULL)
186 *pshared = (*attr)->m_pshared;
191 _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
194 if (attr == NULL || *attr == NULL ||
195 (pshared != PTHREAD_PROCESS_PRIVATE &&
196 pshared != PTHREAD_PROCESS_SHARED))
198 (*attr)->m_pshared = pshared;
203 _pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
207 if (mattr == NULL || *mattr == NULL)
210 *protocol = (*mattr)->m_protocol;
216 _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
220 if (mattr == NULL || *mattr == NULL ||
221 protocol < PTHREAD_PRIO_NONE || protocol > PTHREAD_PRIO_PROTECT)
224 (*mattr)->m_protocol = protocol;
225 (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY;
231 _pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
235 if (mattr == NULL || *mattr == NULL)
237 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
240 *prioceiling = (*mattr)->m_ceiling;
246 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
250 if (mattr == NULL || *mattr == NULL)
252 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
255 (*mattr)->m_ceiling = prioceiling;
261 _pthread_mutexattr_getrobust(pthread_mutexattr_t *mattr, int *robust)
265 if (mattr == NULL || *mattr == NULL) {
269 *robust = (*mattr)->m_robust;
275 _pthread_mutexattr_setrobust(pthread_mutexattr_t *mattr, int robust)
279 if (mattr == NULL || *mattr == NULL) {
281 } else if (robust != PTHREAD_MUTEX_STALLED &&
282 robust != PTHREAD_MUTEX_ROBUST) {
286 (*mattr)->m_robust = robust;