2 * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>.
3 * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include "namespace.h"
37 #include <pthread_np.h>
38 #include "un-namespace.h"
40 #include "thr_private.h"
43 _pthread_mutexattr_init(pthread_mutexattr_t
*attr
)
46 pthread_mutexattr_t pattr
;
48 if ((pattr
= (pthread_mutexattr_t
)
49 malloc(sizeof(struct pthread_mutex_attr
))) == NULL
) {
52 memcpy(pattr
, &_pthread_mutexattr_default
,
53 sizeof(struct pthread_mutex_attr
));
61 _pthread_mutexattr_setkind_np(pthread_mutexattr_t
*attr
, int kind
)
64 if (attr
== NULL
|| *attr
== NULL
) {
68 (*attr
)->m_type
= kind
;
75 _pthread_mutexattr_getkind_np(pthread_mutexattr_t attr
)
89 _pthread_mutexattr_settype(pthread_mutexattr_t
*attr
, int type
)
93 if (attr
== NULL
|| *attr
== NULL
|| type
>= PTHREAD_MUTEX_TYPE_MAX
) {
97 (*attr
)->m_type
= type
;
104 _pthread_mutexattr_gettype(const pthread_mutexattr_t
* __restrict attr
,
105 int * __restrict type
)
109 if (attr
== NULL
|| *attr
== NULL
|| (*attr
)->m_type
>=
110 PTHREAD_MUTEX_TYPE_MAX
) {
113 *type
= (*attr
)->m_type
;
120 _pthread_mutexattr_destroy(pthread_mutexattr_t
*attr
)
123 if (attr
== NULL
|| *attr
== NULL
) {
134 _pthread_mutexattr_getpshared(const pthread_mutexattr_t
* __restrict attr
,
135 int * __restrict pshared
)
138 if (attr
== NULL
|| *attr
== NULL
)
140 *pshared
= PTHREAD_PROCESS_PRIVATE
;
145 _pthread_mutexattr_setpshared(pthread_mutexattr_t
*attr
, int pshared
)
148 if (attr
== NULL
|| *attr
== NULL
)
151 /* Only PTHREAD_PROCESS_PRIVATE is supported. */
152 if (pshared
!= PTHREAD_PROCESS_PRIVATE
)
159 _pthread_mutexattr_getprotocol(const pthread_mutexattr_t
* __restrict mattr
,
160 int * __restrict protocol
)
164 if ((mattr
== NULL
) || (*mattr
== NULL
))
167 *protocol
= (*mattr
)->m_protocol
;
173 _pthread_mutexattr_setprotocol(pthread_mutexattr_t
*mattr
, int protocol
)
177 if ((mattr
== NULL
) || (*mattr
== NULL
) ||
178 (protocol
< PTHREAD_PRIO_NONE
) || (protocol
> PTHREAD_PRIO_PROTECT
))
181 (*mattr
)->m_protocol
= protocol
;
182 (*mattr
)->m_ceiling
= THR_MUTEX_CEIL_PRIORITY
;
188 _pthread_mutexattr_getprioceiling(const pthread_mutexattr_t
* __restrict mattr
,
189 int * __restrict prioceiling
)
193 if ((mattr
== NULL
) || (*mattr
== NULL
))
195 else if ((*mattr
)->m_protocol
!= PTHREAD_PRIO_PROTECT
)
198 *prioceiling
= (*mattr
)->m_ceiling
;
204 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t
*mattr
, int prioceiling
)
208 if ((mattr
== NULL
) || (*mattr
== NULL
))
210 else if ((*mattr
)->m_protocol
!= PTHREAD_PRIO_PROTECT
)
213 (*mattr
)->m_ceiling
= prioceiling
;
218 __strong_reference(_pthread_mutexattr_init
, pthread_mutexattr_init
);
219 __strong_reference(_pthread_mutexattr_setkind_np
, pthread_mutexattr_setkind_np
);
220 __strong_reference(_pthread_mutexattr_getkind_np
, pthread_mutexattr_getkind_np
);
221 __strong_reference(_pthread_mutexattr_gettype
, pthread_mutexattr_gettype
);
222 __strong_reference(_pthread_mutexattr_settype
, pthread_mutexattr_settype
);
223 __strong_reference(_pthread_mutexattr_destroy
, pthread_mutexattr_destroy
);
224 __strong_reference(_pthread_mutexattr_getpshared
, pthread_mutexattr_getpshared
);
225 __strong_reference(_pthread_mutexattr_setpshared
, pthread_mutexattr_setpshared
);
226 __strong_reference(_pthread_mutexattr_getprotocol
, pthread_mutexattr_getprotocol
);
227 __strong_reference(_pthread_mutexattr_setprotocol
, pthread_mutexattr_setprotocol
);
228 __strong_reference(_pthread_mutexattr_getprioceiling
, pthread_mutexattr_getprioceiling
);
229 __strong_reference(_pthread_mutexattr_setprioceiling
, pthread_mutexattr_setprioceiling
);