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
33 * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the author nor the names of any co-contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 #include "namespace.h"
67 #include <pthread_np.h>
68 #include "un-namespace.h"
70 #include "thr_private.h"
72 __weak_reference(_pthread_mutexattr_init, pthread_mutexattr_init);
73 __weak_reference(_pthread_mutexattr_setkind_np, pthread_mutexattr_setkind_np);
74 __weak_reference(_pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np);
75 __weak_reference(_pthread_mutexattr_gettype, pthread_mutexattr_gettype);
76 __weak_reference(_pthread_mutexattr_settype, pthread_mutexattr_settype);
77 __weak_reference(_pthread_mutexattr_destroy, pthread_mutexattr_destroy);
78 __weak_reference(_pthread_mutexattr_getpshared, pthread_mutexattr_getpshared);
79 __weak_reference(_pthread_mutexattr_setpshared, pthread_mutexattr_setpshared);
80 __weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol);
81 __weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
82 __weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling);
83 __weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling);
86 _pthread_mutexattr_init(pthread_mutexattr_t *attr)
89 pthread_mutexattr_t pattr;
91 if ((pattr = (pthread_mutexattr_t)
92 malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
95 memcpy(pattr, &_pthread_mutexattr_default,
96 sizeof(struct pthread_mutex_attr));
104 _pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
107 if (attr == NULL || *attr == NULL) {
111 (*attr)->m_type = kind;
118 _pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
131 _pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
134 if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) {
137 (*attr)->m_type = type;
144 _pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type)
148 if (attr == NULL || *attr == NULL || (*attr)->m_type >=
149 PTHREAD_MUTEX_TYPE_MAX) {
152 *type = (*attr)->m_type;
159 _pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
162 if (attr == NULL || *attr == NULL) {
173 _pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr,
177 if (attr == NULL || *attr == NULL)
180 *pshared = PTHREAD_PROCESS_PRIVATE;
185 _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
188 if (attr == NULL || *attr == NULL)
191 /* Only PTHREAD_PROCESS_PRIVATE is supported. */
192 if (pshared != PTHREAD_PROCESS_PRIVATE)
199 _pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
203 if ((mattr == NULL) || (*mattr == NULL))
206 *protocol = (*mattr)->m_protocol;
212 _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
216 if ((mattr == NULL) || (*mattr == NULL) ||
217 (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
220 (*mattr)->m_protocol = protocol;
221 (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY;
227 _pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
231 if ((mattr == NULL) || (*mattr == NULL))
233 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
236 *prioceiling = (*mattr)->m_ceiling;
242 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
246 if ((mattr == NULL) || (*mattr == NULL))
248 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
251 (*mattr)->m_ceiling = prioceiling;