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(const pthread_mutexattr_t * __restrict attr,
152 int * __restrict type)
156 if (attr == NULL || *attr == NULL || (*attr)->m_type >=
157 PTHREAD_MUTEX_TYPE_MAX) {
160 *type = (*attr)->m_type;
167 _pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
170 if (attr == NULL || *attr == NULL) {
181 _pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
185 if (attr == NULL || *attr == NULL)
187 *pshared = (*attr)->m_pshared;
192 _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
195 if (attr == NULL || *attr == NULL ||
196 (pshared != PTHREAD_PROCESS_PRIVATE &&
197 pshared != PTHREAD_PROCESS_SHARED))
199 (*attr)->m_pshared = pshared;
204 _pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict mattr,
205 int * __restrict protocol)
209 if (mattr == NULL || *mattr == NULL)
212 *protocol = (*mattr)->m_protocol;
218 _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
222 if (mattr == NULL || *mattr == NULL ||
223 protocol < PTHREAD_PRIO_NONE || protocol > PTHREAD_PRIO_PROTECT)
226 (*mattr)->m_protocol = protocol;
227 (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY;
233 _pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict mattr,
234 int * __restrict prioceiling)
238 if (mattr == NULL || *mattr == NULL)
240 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
243 *prioceiling = (*mattr)->m_ceiling;
249 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
253 if (mattr == NULL || *mattr == NULL)
255 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
258 (*mattr)->m_ceiling = prioceiling;
264 _pthread_mutexattr_getrobust(pthread_mutexattr_t *mattr, int *robust)
268 if (mattr == NULL || *mattr == NULL) {
272 *robust = (*mattr)->m_robust;
278 _pthread_mutexattr_setrobust(pthread_mutexattr_t *mattr, int robust)
282 if (mattr == NULL || *mattr == NULL) {
284 } else if (robust != PTHREAD_MUTEX_STALLED &&
285 robust != PTHREAD_MUTEX_ROBUST) {
289 (*mattr)->m_robust = robust;