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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
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
38 pthread_condattr_init(pthread_condattr_t
*attr
)
42 if ((ap
= lmalloc(sizeof (cvattr_t
))) == NULL
)
44 ap
->pshared
= DEFAULT_TYPE
;
45 ap
->clockid
= CLOCK_REALTIME
;
46 attr
->__pthread_condattrp
= ap
;
51 * pthread_condattr_destroy: frees the cond attribute object and
52 * invalidates it with NULL value.
55 pthread_condattr_destroy(pthread_condattr_t
*attr
)
57 if (attr
== NULL
|| attr
->__pthread_condattrp
== NULL
)
59 lfree(attr
->__pthread_condattrp
, sizeof (cvattr_t
));
60 attr
->__pthread_condattrp
= NULL
;
65 * pthread_condattr_setclock: sets the clockid attribute.
68 pthread_condattr_setclock(pthread_condattr_t
*attr
, clockid_t clock_id
)
72 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
73 (clock_id
== CLOCK_REALTIME
|| clock_id
== CLOCK_HIGHRES
)) {
74 ap
->clockid
= clock_id
;
81 * pthread_condattr_getclock: gets the shared attr.
84 pthread_condattr_getclock(const pthread_condattr_t
*attr
, clockid_t
*clock_id
)
88 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
90 *clock_id
= ap
->clockid
;
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
)
106 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
107 (pshared
== PTHREAD_PROCESS_PRIVATE
||
108 pshared
== PTHREAD_PROCESS_SHARED
)) {
109 ap
->pshared
= pshared
;
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
)
124 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
126 *pshared
= ap
->pshared
;
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
)
147 clock_id
= CLOCK_REALTIME
;
148 } else if ((ap
= attr
->__pthread_condattrp
) != NULL
) {
150 clock_id
= ap
->clockid
;
155 if (clock_id
!= CLOCK_REALTIME
&& clock_id
!= CLOCK_HIGHRES
)
157 else if ((error
= cond_init((cond_t
*)cond
, type
, NULL
)) == 0)
158 ((cond_t
*)cond
)->cond_clockid
= (uint8_t)clock_id
;