dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / port / threads / pthr_rwlock.c
blob44be459259bd1908e3fb5e436e8e1f209b86f4dc
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include "lint.h"
28 #include "thr_uberdata.h"
31 * UNIX98
32 * pthread_rwlockattr_init: allocates the mutex attribute object and
33 * initializes it with the default values.
35 int
36 pthread_rwlockattr_init(pthread_rwlockattr_t *attr)
38 rwlattr_t *ap;
40 if ((ap = lmalloc(sizeof (rwlattr_t))) == NULL)
41 return (ENOMEM);
42 ap->pshared = PTHREAD_PROCESS_PRIVATE;
43 attr->__pthread_rwlockattrp = ap;
44 return (0);
48 * UNIX98
49 * pthread_rwlockattr_destroy: frees the rwlock attribute object and
50 * invalidates it with NULL value.
52 int
53 pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr)
55 if (attr == NULL || attr->__pthread_rwlockattrp == NULL)
56 return (EINVAL);
57 lfree(attr->__pthread_rwlockattrp, sizeof (rwlattr_t));
58 attr->__pthread_rwlockattrp = NULL;
59 return (0);
63 * UNIX98
64 * pthread_rwlockattr_setpshared: sets the shared attr to PRIVATE or SHARED.
66 int
67 pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared)
69 rwlattr_t *ap;
71 if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
72 (pshared == PTHREAD_PROCESS_PRIVATE ||
73 pshared == PTHREAD_PROCESS_SHARED)) {
74 ap->pshared = pshared;
75 return (0);
77 return (EINVAL);
81 * UNIX98
82 * pthread_rwlockattr_getpshared: gets the shared attr.
84 int
85 pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared)
87 rwlattr_t *ap;
89 if (attr != NULL && (ap = attr->__pthread_rwlockattrp) != NULL &&
90 pshared != NULL) {
91 *pshared = ap->pshared;
92 return (0);
94 return (EINVAL);
98 * UNIX98
99 * pthread_rwlock_init: Initializes the rwlock object. It copies the
100 * pshared attr into type argument and calls rwlock_init().
103 pthread_rwlock_init(pthread_rwlock_t *_RESTRICT_KYWD rwlock,
104 const pthread_rwlockattr_t *_RESTRICT_KYWD attr)
106 rwlattr_t *ap;
107 int type;
109 if (attr == NULL)
110 type = PTHREAD_PROCESS_PRIVATE;
111 else if ((ap = attr->__pthread_rwlockattrp) != NULL)
112 type = ap->pshared;
113 else
114 return (EINVAL);
116 return (rwlock_init((rwlock_t *)rwlock, type, NULL));