8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libc / port / threads / pthr_cond.c
blob22f81af8ffe1a60e1862edf43f450e98968986a3
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 * pthread_condattr_init: allocates the cond attribute object and
32 * initializes it with the default values.
34 #pragma weak _pthread_condattr_init = pthread_condattr_init
35 int
36 pthread_condattr_init(pthread_condattr_t *attr)
38 cvattr_t *ap;
40 if ((ap = lmalloc(sizeof (cvattr_t))) == NULL)
41 return (ENOMEM);
42 ap->pshared = PTHREAD_PROCESS_PRIVATE;
43 ap->clockid = CLOCK_REALTIME;
44 attr->__pthread_condattrp = ap;
45 return (0);
49 * pthread_condattr_destroy: frees the cond attribute object and
50 * invalidates it with NULL value.
52 int
53 pthread_condattr_destroy(pthread_condattr_t *attr)
55 if (attr == NULL || attr->__pthread_condattrp == NULL)
56 return (EINVAL);
57 lfree(attr->__pthread_condattrp, sizeof (cvattr_t));
58 attr->__pthread_condattrp = NULL;
59 return (0);
63 * pthread_condattr_setclock: sets the clockid attribute.
65 int
66 pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
68 cvattr_t *ap;
70 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
71 (clock_id == CLOCK_REALTIME || clock_id == CLOCK_HIGHRES)) {
72 ap->clockid = clock_id;
73 return (0);
75 return (EINVAL);
79 * pthread_condattr_getclock: gets the shared attr.
81 int
82 pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
84 cvattr_t *ap;
86 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
87 clock_id != NULL) {
88 *clock_id = ap->clockid;
89 return (0);
91 return (EINVAL);
96 * pthread_condattr_setpshared: sets the shared attr to PRIVATE or SHARED.
97 * This is equivalent to setting USYNC_PROCESS/USYNC_THREAD flag in cond_init().
99 int
100 pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
102 cvattr_t *ap;
104 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
105 (pshared == PTHREAD_PROCESS_PRIVATE ||
106 pshared == PTHREAD_PROCESS_SHARED)) {
107 ap->pshared = pshared;
108 return (0);
110 return (EINVAL);
114 * pthread_condattr_getpshared: gets the shared attr.
116 #pragma weak _pthread_condattr_getpshared = pthread_condattr_getpshared
118 pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared)
120 cvattr_t *ap;
122 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
123 pshared != NULL) {
124 *pshared = ap->pshared;
125 return (0);
127 return (EINVAL);
131 * pthread_cond_init: Initializes the cond object. It copies the
132 * pshared attr into type argument and calls cond_init().
134 #pragma weak _pthread_cond_init = pthread_cond_init
136 pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
138 cvattr_t *ap;
139 int type;
140 clockid_t clock_id;
141 int error;
143 if (attr == NULL) {
144 type = PTHREAD_PROCESS_PRIVATE;
145 clock_id = CLOCK_REALTIME;
146 } else if ((ap = attr->__pthread_condattrp) != NULL) {
147 type = ap->pshared;
148 clock_id = ap->clockid;
149 } else {
150 return (EINVAL);
153 if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_HIGHRES)
154 error = EINVAL;
155 else if ((error = cond_init((cond_t *)cond, type, NULL)) == 0)
156 ((cond_t *)cond)->cond_clockid = (uint8_t)clock_id;
158 return (error);