1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include "lint.h" 30 #include "thr_uberdata.h" 31 32 /* 33 * UNIX98 34 * pthread_rwlockattr_init: allocates the mutex attribute object and 35 * initializes it with the default values. 36 */ 37 int 38 pthread_rwlockattr_init(pthread_rwlockattr_t *attr) 39 { 40 rwlattr_t *ap; 41 42 if ((ap = lmalloc(sizeof (rwlattr_t))) == NULL) 43 return (ENOMEM); 44 ap->pshared = DEFAULT_TYPE; 45 attr->__pthread_rwlockattrp = ap; 46 return (0); 47 } 48 49 /* 50 * UNIX98 51 * pthread_rwlockattr_destroy: frees the rwlock attribute object and 52 * invalidates it with NULL value. 53 */ 54 int 55 pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) 56 { 57 if (attr == NULL || attr->__pthread_rwlockattrp == NULL) 58 return (EINVAL); 59 lfree(attr->__pthread_rwlockattrp, sizeof (rwlattr_t)); 60 attr->__pthread_rwlockattrp = NULL; 61 return (0); 62 } 63 64 /* 65 * UNIX98 66 * pthread_rwlockattr_setpshared: sets the shared attr to PRIVATE or SHARED. 67 */ 68 int 69 pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) 70 { 71 rwlattr_t *ap; 72 73 if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL && 74 (pshared == PTHREAD_PROCESS_PRIVATE || 75 pshared == PTHREAD_PROCESS_SHARED)) { 76 ap->pshared = pshared; 77 return (0); 78 } 79 return (EINVAL); 80 } 81 82 /* 83 * UNIX98 84 * pthread_rwlockattr_getpshared: gets the shared attr. 85 */ 86 int 87 pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared) 88 { 89 rwlattr_t *ap; 90 91 if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL && 92 pshared != NULL) { 93 *pshared = ap->pshared; 94 return (0); 95 } 96 return (EINVAL); 97 } 98 99 /* 100 * UNIX98 101 * pthread_rwlock_init: Initializes the rwlock object. It copies the 102 * pshared attr into type argument and calls rwlock_init(). 103 */ 104 int 105 pthread_rwlock_init(pthread_rwlock_t *_RESTRICT_KYWD rwlock, 106 const pthread_rwlockattr_t *_RESTRICT_KYWD attr) 107 { 108 rwlattr_t *ap; 109 int type; 110 111 if (attr == NULL) 112 type = DEFAULT_TYPE; 113 else if ((ap = attr->__pthread_rwlockattrp) != NULL) 114 type = ap->pshared; 115 else 116 return (EINVAL); 117 118 return (rwlock_init((rwlock_t *)rwlock, type, NULL)); 119 } 120