10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include "lint.h"
300Sstevel@tonic-gate #include "thr_uberdata.h"
310Sstevel@tonic-gate
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate * UNIX98
340Sstevel@tonic-gate * pthread_rwlockattr_init: allocates the mutex attribute object and
350Sstevel@tonic-gate * initializes it with the default values.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate int
pthread_rwlockattr_init(pthread_rwlockattr_t * attr)38*6812Sraf pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate rwlattr_t *ap;
410Sstevel@tonic-gate
420Sstevel@tonic-gate if ((ap = lmalloc(sizeof (rwlattr_t))) == NULL)
430Sstevel@tonic-gate return (ENOMEM);
440Sstevel@tonic-gate ap->pshared = DEFAULT_TYPE;
450Sstevel@tonic-gate attr->__pthread_rwlockattrp = ap;
460Sstevel@tonic-gate return (0);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * UNIX98
510Sstevel@tonic-gate * pthread_rwlockattr_destroy: frees the rwlock attribute object and
520Sstevel@tonic-gate * invalidates it with NULL value.
530Sstevel@tonic-gate */
540Sstevel@tonic-gate int
pthread_rwlockattr_destroy(pthread_rwlockattr_t * attr)55*6812Sraf pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate if (attr == NULL || attr->__pthread_rwlockattrp == NULL)
580Sstevel@tonic-gate return (EINVAL);
590Sstevel@tonic-gate lfree(attr->__pthread_rwlockattrp, sizeof (rwlattr_t));
600Sstevel@tonic-gate attr->__pthread_rwlockattrp = NULL;
610Sstevel@tonic-gate return (0);
620Sstevel@tonic-gate }
630Sstevel@tonic-gate
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate * UNIX98
660Sstevel@tonic-gate * pthread_rwlockattr_setpshared: sets the shared attr to PRIVATE or SHARED.
670Sstevel@tonic-gate */
680Sstevel@tonic-gate int
pthread_rwlockattr_setpshared(pthread_rwlockattr_t * attr,int pshared)69*6812Sraf pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
700Sstevel@tonic-gate {
710Sstevel@tonic-gate rwlattr_t *ap;
720Sstevel@tonic-gate
730Sstevel@tonic-gate if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
740Sstevel@tonic-gate (pshared == PTHREAD_PROCESS_PRIVATE ||
750Sstevel@tonic-gate pshared == PTHREAD_PROCESS_SHARED)) {
760Sstevel@tonic-gate ap->pshared = pshared;
770Sstevel@tonic-gate return (0);
780Sstevel@tonic-gate }
790Sstevel@tonic-gate return (EINVAL);
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * UNIX98
840Sstevel@tonic-gate * pthread_rwlockattr_getpshared: gets the shared attr.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate int
pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * attr,int * pshared)87*6812Sraf pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate rwlattr_t *ap;
900Sstevel@tonic-gate
910Sstevel@tonic-gate if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
920Sstevel@tonic-gate pshared != NULL) {
930Sstevel@tonic-gate *pshared = ap->pshared;
940Sstevel@tonic-gate return (0);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate return (EINVAL);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate * UNIX98
1010Sstevel@tonic-gate * pthread_rwlock_init: Initializes the rwlock object. It copies the
1020Sstevel@tonic-gate * pshared attr into type argument and calls rwlock_init().
1030Sstevel@tonic-gate */
1040Sstevel@tonic-gate int
pthread_rwlock_init(pthread_rwlock_t * _RESTRICT_KYWD rwlock,const pthread_rwlockattr_t * _RESTRICT_KYWD attr)105*6812Sraf pthread_rwlock_init(pthread_rwlock_t *_RESTRICT_KYWD rwlock,
106*6812Sraf const pthread_rwlockattr_t *_RESTRICT_KYWD attr)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate rwlattr_t *ap;
1090Sstevel@tonic-gate int type;
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate if (attr == NULL)
1120Sstevel@tonic-gate type = DEFAULT_TYPE;
1130Sstevel@tonic-gate else if ((ap = attr->__pthread_rwlockattrp) != NULL)
1140Sstevel@tonic-gate type = ap->pshared;
1150Sstevel@tonic-gate else
1160Sstevel@tonic-gate return (EINVAL);
1170Sstevel@tonic-gate
118*6812Sraf return (rwlock_init((rwlock_t *)rwlock, type, NULL));
1190Sstevel@tonic-gate }
120