17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include "lint.h"
287c478bd9Sstevel@tonic-gate #include "thr_uberdata.h"
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * UNIX98
327c478bd9Sstevel@tonic-gate * pthread_rwlockattr_init: allocates the mutex attribute object and
337c478bd9Sstevel@tonic-gate * initializes it with the default values.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate int
pthread_rwlockattr_init(pthread_rwlockattr_t * attr)367257d1b4Sraf pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
377c478bd9Sstevel@tonic-gate {
387c478bd9Sstevel@tonic-gate rwlattr_t *ap;
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate if ((ap = lmalloc(sizeof (rwlattr_t))) == NULL)
417c478bd9Sstevel@tonic-gate return (ENOMEM);
42*a90d75b8SRichard PALO ap->pshared = PTHREAD_PROCESS_PRIVATE;
437c478bd9Sstevel@tonic-gate attr->__pthread_rwlockattrp = ap;
447c478bd9Sstevel@tonic-gate return (0);
457c478bd9Sstevel@tonic-gate }
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate * UNIX98
497c478bd9Sstevel@tonic-gate * pthread_rwlockattr_destroy: frees the rwlock attribute object and
507c478bd9Sstevel@tonic-gate * invalidates it with NULL value.
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate int
pthread_rwlockattr_destroy(pthread_rwlockattr_t * attr)537257d1b4Sraf pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate if (attr == NULL || attr->__pthread_rwlockattrp == NULL)
567c478bd9Sstevel@tonic-gate return (EINVAL);
577c478bd9Sstevel@tonic-gate lfree(attr->__pthread_rwlockattrp, sizeof (rwlattr_t));
587c478bd9Sstevel@tonic-gate attr->__pthread_rwlockattrp = NULL;
597c478bd9Sstevel@tonic-gate return (0);
607c478bd9Sstevel@tonic-gate }
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate * UNIX98
647c478bd9Sstevel@tonic-gate * pthread_rwlockattr_setpshared: sets the shared attr to PRIVATE or SHARED.
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate int
pthread_rwlockattr_setpshared(pthread_rwlockattr_t * attr,int pshared)677257d1b4Sraf pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate rwlattr_t *ap;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
727c478bd9Sstevel@tonic-gate (pshared == PTHREAD_PROCESS_PRIVATE ||
737c478bd9Sstevel@tonic-gate pshared == PTHREAD_PROCESS_SHARED)) {
747c478bd9Sstevel@tonic-gate ap->pshared = pshared;
757c478bd9Sstevel@tonic-gate return (0);
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate return (EINVAL);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * UNIX98
827c478bd9Sstevel@tonic-gate * pthread_rwlockattr_getpshared: gets the shared attr.
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate int
pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * attr,int * pshared)857257d1b4Sraf pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate rwlattr_t *ap;
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
907c478bd9Sstevel@tonic-gate pshared != NULL) {
917c478bd9Sstevel@tonic-gate *pshared = ap->pshared;
927c478bd9Sstevel@tonic-gate return (0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate return (EINVAL);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate * UNIX98
997c478bd9Sstevel@tonic-gate * pthread_rwlock_init: Initializes the rwlock object. It copies the
1007c478bd9Sstevel@tonic-gate * pshared attr into type argument and calls rwlock_init().
1017c478bd9Sstevel@tonic-gate */
1027c478bd9Sstevel@tonic-gate int
pthread_rwlock_init(pthread_rwlock_t * _RESTRICT_KYWD rwlock,const pthread_rwlockattr_t * _RESTRICT_KYWD attr)1037257d1b4Sraf pthread_rwlock_init(pthread_rwlock_t *_RESTRICT_KYWD rwlock,
1047257d1b4Sraf const pthread_rwlockattr_t *_RESTRICT_KYWD attr)
1057c478bd9Sstevel@tonic-gate {
1067c478bd9Sstevel@tonic-gate rwlattr_t *ap;
1077c478bd9Sstevel@tonic-gate int type;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate if (attr == NULL)
110*a90d75b8SRichard PALO type = PTHREAD_PROCESS_PRIVATE;
1117c478bd9Sstevel@tonic-gate else if ((ap = attr->__pthread_rwlockattrp) != NULL)
1127c478bd9Sstevel@tonic-gate type = ap->pshared;
1137c478bd9Sstevel@tonic-gate else
1147c478bd9Sstevel@tonic-gate return (EINVAL);
1157c478bd9Sstevel@tonic-gate
1167257d1b4Sraf return (rwlock_init((rwlock_t *)rwlock, type, NULL));
1177c478bd9Sstevel@tonic-gate }
118