<pthread.h>: Add missing 'const' to four functions.
[dragonfly.git] / lib / libthread_xu / thread / thr_mutexattr.c
blob25a6966b3e2ec40341e5c2271d3c21a77004b0f7
1 /*
2 * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>.
3 * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
28 * SUCH DAMAGE.
32 #include "namespace.h"
33 #include <string.h>
34 #include <stdlib.h>
35 #include <errno.h>
36 #include <pthread.h>
37 #include <pthread_np.h>
38 #include "un-namespace.h"
40 #include "thr_private.h"
42 int
43 _pthread_mutexattr_init(pthread_mutexattr_t *attr)
45 int ret;
46 pthread_mutexattr_t pattr;
48 if ((pattr = (pthread_mutexattr_t)
49 malloc(sizeof(struct pthread_mutex_attr))) == NULL) {
50 ret = ENOMEM;
51 } else {
52 memcpy(pattr, &_pthread_mutexattr_default,
53 sizeof(struct pthread_mutex_attr));
54 *attr = pattr;
55 ret = 0;
57 return (ret);
60 int
61 _pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind)
63 int ret;
64 if (attr == NULL || *attr == NULL) {
65 errno = EINVAL;
66 ret = -1;
67 } else {
68 (*attr)->m_type = kind;
69 ret = 0;
71 return(ret);
74 int
75 _pthread_mutexattr_getkind_np(pthread_mutexattr_t attr)
77 int ret;
79 if (attr == NULL) {
80 errno = EINVAL;
81 ret = -1;
82 } else {
83 ret = attr->m_type;
85 return (ret);
88 int
89 _pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
91 int ret;
93 if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) {
94 errno = EINVAL;
95 ret = -1;
96 } else {
97 (*attr)->m_type = type;
98 ret = 0;
100 return (ret);
104 _pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict attr,
105 int * __restrict type)
107 int ret;
109 if (attr == NULL || *attr == NULL || (*attr)->m_type >=
110 PTHREAD_MUTEX_TYPE_MAX) {
111 ret = EINVAL;
112 } else {
113 *type = (*attr)->m_type;
114 ret = 0;
116 return (ret);
120 _pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
122 int ret;
123 if (attr == NULL || *attr == NULL) {
124 ret = EINVAL;
125 } else {
126 free(*attr);
127 *attr = NULL;
128 ret = 0;
130 return (ret);
134 _pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict attr,
135 int * __restrict pshared)
138 if (attr == NULL || *attr == NULL)
139 return (EINVAL);
140 *pshared = PTHREAD_PROCESS_PRIVATE;
141 return (0);
145 _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
148 if (attr == NULL || *attr == NULL)
149 return (EINVAL);
151 /* Only PTHREAD_PROCESS_PRIVATE is supported. */
152 if (pshared != PTHREAD_PROCESS_PRIVATE)
153 return (EINVAL);
155 return (0);
159 _pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict mattr,
160 int * __restrict protocol)
162 int ret = 0;
164 if ((mattr == NULL) || (*mattr == NULL))
165 ret = EINVAL;
166 else
167 *protocol = (*mattr)->m_protocol;
169 return (ret);
173 _pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
175 int ret = 0;
177 if ((mattr == NULL) || (*mattr == NULL) ||
178 (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
179 ret = EINVAL;
180 else {
181 (*mattr)->m_protocol = protocol;
182 (*mattr)->m_ceiling = THR_MUTEX_CEIL_PRIORITY;
184 return (ret);
188 _pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict mattr,
189 int * __restrict prioceiling)
191 int ret = 0;
193 if ((mattr == NULL) || (*mattr == NULL))
194 ret = EINVAL;
195 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
196 ret = EINVAL;
197 else
198 *prioceiling = (*mattr)->m_ceiling;
200 return (ret);
204 _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
206 int ret = 0;
208 if ((mattr == NULL) || (*mattr == NULL))
209 ret = EINVAL;
210 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
211 ret = EINVAL;
212 else
213 (*mattr)->m_ceiling = prioceiling;
215 return (ret);
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);