thr_mutexattr.c (297706) | thr_mutexattr.c (300043) |
---|---|
1/* 2 * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 44 unchanged lines hidden (view full) --- 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 56 * SUCH DAMAGE. 57 * 58 */ 59 60#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1996 Jeffrey Hsu <hsu@freebsd.org>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 44 unchanged lines hidden (view full) --- 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 56 * SUCH DAMAGE. 57 * 58 */ 59 60#include <sys/cdefs.h> |
61__FBSDID("$FreeBSD: head/lib/libthr/thread/thr_mutexattr.c 297706 2016-04-08 11:15:26Z kib $"); | 61__FBSDID("$FreeBSD: head/lib/libthr/thread/thr_mutexattr.c 300043 2016-05-17 09:56:22Z kib $"); |
62 63#include "namespace.h" 64#include <string.h> 65#include <stdlib.h> 66#include <errno.h> 67#include <pthread.h> 68#include <pthread_np.h> 69#include "un-namespace.h" --- 5 unchanged lines hidden (view full) --- 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); | 62 63#include "namespace.h" 64#include <string.h> 65#include <stdlib.h> 66#include <errno.h> 67#include <pthread.h> 68#include <pthread_np.h> 69#include "un-namespace.h" --- 5 unchanged lines hidden (view full) --- 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, pthread_mutexattr_getprioceiling); 84__weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling); | 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); |
85 86int 87_pthread_mutexattr_init(pthread_mutexattr_t *attr) 88{ 89 int ret; 90 pthread_mutexattr_t pattr; 91 92 if ((pattr = (pthread_mutexattr_t) --- 21 unchanged lines hidden (view full) --- 114 } 115 return(ret); 116} 117 118int 119_pthread_mutexattr_getkind_np(pthread_mutexattr_t attr) 120{ 121 int ret; | 89 90int 91_pthread_mutexattr_init(pthread_mutexattr_t *attr) 92{ 93 int ret; 94 pthread_mutexattr_t pattr; 95 96 if ((pattr = (pthread_mutexattr_t) --- 21 unchanged lines hidden (view full) --- 118 } 119 return(ret); 120} 121 122int 123_pthread_mutexattr_getkind_np(pthread_mutexattr_t attr) 124{ 125 int ret; |
126 |
|
122 if (attr == NULL) { 123 errno = EINVAL; 124 ret = -1; 125 } else { 126 ret = attr->m_type; 127 } | 127 if (attr == NULL) { 128 errno = EINVAL; 129 ret = -1; 130 } else { 131 ret = attr->m_type; 132 } |
128 return(ret); | 133 return (ret); |
129} 130 131int 132_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) 133{ 134 int ret; | 134} 135 136int 137_pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) 138{ 139 int ret; |
140 |
|
135 if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) { 136 ret = EINVAL; 137 } else { 138 (*attr)->m_type = type; 139 ret = 0; 140 } | 141 if (attr == NULL || *attr == NULL || type >= PTHREAD_MUTEX_TYPE_MAX) { 142 ret = EINVAL; 143 } else { 144 (*attr)->m_type = type; 145 ret = 0; 146 } |
141 return(ret); | 147 return (ret); |
142} 143 144int 145_pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type) 146{ 147 int ret; 148 149 if (attr == NULL || *attr == NULL || (*attr)->m_type >= 150 PTHREAD_MUTEX_TYPE_MAX) { 151 ret = EINVAL; 152 } else { 153 *type = (*attr)->m_type; 154 ret = 0; 155 } | 148} 149 150int 151_pthread_mutexattr_gettype(pthread_mutexattr_t *attr, int *type) 152{ 153 int ret; 154 155 if (attr == NULL || *attr == NULL || (*attr)->m_type >= 156 PTHREAD_MUTEX_TYPE_MAX) { 157 ret = EINVAL; 158 } else { 159 *type = (*attr)->m_type; 160 ret = 0; 161 } |
156 return ret; | 162 return (ret); |
157} 158 159int 160_pthread_mutexattr_destroy(pthread_mutexattr_t *attr) 161{ 162 int ret; 163 if (attr == NULL || *attr == NULL) { 164 ret = EINVAL; 165 } else { 166 free(*attr); 167 *attr = NULL; 168 ret = 0; 169 } | 163} 164 165int 166_pthread_mutexattr_destroy(pthread_mutexattr_t *attr) 167{ 168 int ret; 169 if (attr == NULL || *attr == NULL) { 170 ret = EINVAL; 171 } else { 172 free(*attr); 173 *attr = NULL; 174 ret = 0; 175 } |
170 return(ret); | 176 return (ret); |
171} 172 173int 174_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, 175 int *pshared) 176{ 177 178 if (attr == NULL || *attr == NULL) --- 14 unchanged lines hidden (view full) --- 193 return (0); 194} 195 196int 197_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol) 198{ 199 int ret = 0; 200 | 177} 178 179int 180_pthread_mutexattr_getpshared(const pthread_mutexattr_t *attr, 181 int *pshared) 182{ 183 184 if (attr == NULL || *attr == NULL) --- 14 unchanged lines hidden (view full) --- 199 return (0); 200} 201 202int 203_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol) 204{ 205 int ret = 0; 206 |
201 if ((mattr == NULL) || (*mattr == NULL)) | 207 if (mattr == NULL || *mattr == NULL) |
202 ret = EINVAL; 203 else 204 *protocol = (*mattr)->m_protocol; 205 | 208 ret = EINVAL; 209 else 210 *protocol = (*mattr)->m_protocol; 211 |
206 return(ret); | 212 return (ret); |
207} 208 209int 210_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol) 211{ 212 int ret = 0; 213 | 213} 214 215int 216_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol) 217{ 218 int ret = 0; 219 |
214 if ((mattr == NULL) || (*mattr == NULL) || 215 (protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT)) | 220 if (mattr == NULL || *mattr == NULL || 221 protocol < PTHREAD_PRIO_NONE || protocol > PTHREAD_PRIO_PROTECT) |
216 ret = EINVAL; 217 else { 218 (*mattr)->m_protocol = protocol; 219 (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY; 220 } | 222 ret = EINVAL; 223 else { 224 (*mattr)->m_protocol = protocol; 225 (*mattr)->m_ceiling = THR_MAX_RR_PRIORITY; 226 } |
221 return(ret); | 227 return (ret); |
222} 223 224int 225_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling) 226{ 227 int ret = 0; 228 | 228} 229 230int 231_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling) 232{ 233 int ret = 0; 234 |
229 if ((mattr == NULL) || (*mattr == NULL)) | 235 if (mattr == NULL || *mattr == NULL) |
230 ret = EINVAL; 231 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 232 ret = EINVAL; 233 else 234 *prioceiling = (*mattr)->m_ceiling; 235 | 236 ret = EINVAL; 237 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 238 ret = EINVAL; 239 else 240 *prioceiling = (*mattr)->m_ceiling; 241 |
236 return(ret); | 242 return (ret); |
237} 238 239int 240_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling) 241{ 242 int ret = 0; 243 | 243} 244 245int 246_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling) 247{ 248 int ret = 0; 249 |
244 if ((mattr == NULL) || (*mattr == NULL)) | 250 if (mattr == NULL || *mattr == NULL) |
245 ret = EINVAL; 246 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 247 ret = EINVAL; 248 else 249 (*mattr)->m_ceiling = prioceiling; 250 | 251 ret = EINVAL; 252 else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT) 253 ret = EINVAL; 254 else 255 (*mattr)->m_ceiling = prioceiling; 256 |
251 return(ret); | 257 return (ret); |
252} 253 | 258} 259 |
260int 261_pthread_mutexattr_getrobust(pthread_mutexattr_t *mattr, int *robust) 262{ 263 int ret; 264 265 if (mattr == NULL || *mattr == NULL) { 266 ret = EINVAL; 267 } else { 268 ret = 0; 269 *robust = (*mattr)->m_robust; 270 } 271 return (ret); 272} 273 274int 275_pthread_mutexattr_setrobust(pthread_mutexattr_t *mattr, int robust) 276{ 277 int ret; 278 279 if (mattr == NULL || *mattr == NULL) { 280 ret = EINVAL; 281 } else if (robust != PTHREAD_MUTEX_STALLED && 282 robust != PTHREAD_MUTEX_ROBUST) { 283 ret = EINVAL; 284 } else { 285 ret = 0; 286 (*mattr)->m_robust = robust; 287 } 288 return (ret); 289} 290 |
|