6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / lib / libc / port / threads / pthr_cond.c
blobb22bc27cf2b9a9bd3c2c564832855b19375bc02e
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 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "lint.h"
30 #include "thr_uberdata.h"
33 * pthread_condattr_init: allocates the cond attribute object and
34 * initializes it with the default values.
36 #pragma weak _pthread_condattr_init = pthread_condattr_init
37 int
38 pthread_condattr_init(pthread_condattr_t *attr)
40 cvattr_t *ap;
42 if ((ap = lmalloc(sizeof (cvattr_t))) == NULL)
43 return (ENOMEM);
44 ap->pshared = DEFAULT_TYPE;
45 ap->clockid = CLOCK_REALTIME;
46 attr->__pthread_condattrp = ap;
47 return (0);
51 * pthread_condattr_destroy: frees the cond attribute object and
52 * invalidates it with NULL value.
54 int
55 pthread_condattr_destroy(pthread_condattr_t *attr)
57 if (attr == NULL || attr->__pthread_condattrp == NULL)
58 return (EINVAL);
59 lfree(attr->__pthread_condattrp, sizeof (cvattr_t));
60 attr->__pthread_condattrp = NULL;
61 return (0);
65 * pthread_condattr_setclock: sets the clockid attribute.
67 int
68 pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
70 cvattr_t *ap;
72 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
73 (clock_id == CLOCK_REALTIME || clock_id == CLOCK_HIGHRES)) {
74 ap->clockid = clock_id;
75 return (0);
77 return (EINVAL);
81 * pthread_condattr_getclock: gets the shared attr.
83 int
84 pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
86 cvattr_t *ap;
88 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
89 clock_id != NULL) {
90 *clock_id = ap->clockid;
91 return (0);
93 return (EINVAL);
98 * pthread_condattr_setpshared: sets the shared attr to PRIVATE or SHARED.
99 * This is equivalent to setting USYNC_PROCESS/USYNC_THREAD flag in cond_init().
102 pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
104 cvattr_t *ap;
106 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
107 (pshared == PTHREAD_PROCESS_PRIVATE ||
108 pshared == PTHREAD_PROCESS_SHARED)) {
109 ap->pshared = pshared;
110 return (0);
112 return (EINVAL);
116 * pthread_condattr_getpshared: gets the shared attr.
118 #pragma weak _pthread_condattr_getpshared = pthread_condattr_getpshared
120 pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared)
122 cvattr_t *ap;
124 if (attr != NULL && (ap = attr->__pthread_condattrp) != NULL &&
125 pshared != NULL) {
126 *pshared = ap->pshared;
127 return (0);
129 return (EINVAL);
133 * pthread_cond_init: Initializes the cond object. It copies the
134 * pshared attr into type argument and calls cond_init().
136 #pragma weak _pthread_cond_init = pthread_cond_init
138 pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
140 cvattr_t *ap;
141 int type;
142 clockid_t clock_id;
143 int error;
145 if (attr == NULL) {
146 type = DEFAULT_TYPE;
147 clock_id = CLOCK_REALTIME;
148 } else if ((ap = attr->__pthread_condattrp) != NULL) {
149 type = ap->pshared;
150 clock_id = ap->clockid;
151 } else {
152 return (EINVAL);
155 if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_HIGHRES)
156 error = EINVAL;
157 else if ((error = cond_init((cond_t *)cond, type, NULL)) == 0)
158 ((cond_t *)cond)->cond_clockid = (uint8_t)clock_id;
160 return (error);