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.
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
36 pthread_condattr_init(pthread_condattr_t
*attr
)
40 if ((ap
= lmalloc(sizeof (cvattr_t
))) == NULL
)
42 ap
->pshared
= PTHREAD_PROCESS_PRIVATE
;
43 ap
->clockid
= CLOCK_REALTIME
;
44 attr
->__pthread_condattrp
= ap
;
49 * pthread_condattr_destroy: frees the cond attribute object and
50 * invalidates it with NULL value.
53 pthread_condattr_destroy(pthread_condattr_t
*attr
)
55 if (attr
== NULL
|| attr
->__pthread_condattrp
== NULL
)
57 lfree(attr
->__pthread_condattrp
, sizeof (cvattr_t
));
58 attr
->__pthread_condattrp
= NULL
;
63 * pthread_condattr_setclock: sets the clockid attribute.
66 pthread_condattr_setclock(pthread_condattr_t
*attr
, clockid_t clock_id
)
70 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
71 (clock_id
== CLOCK_REALTIME
|| clock_id
== CLOCK_HIGHRES
)) {
72 ap
->clockid
= clock_id
;
79 * pthread_condattr_getclock: gets the shared attr.
82 pthread_condattr_getclock(const pthread_condattr_t
*attr
, clockid_t
*clock_id
)
86 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
88 *clock_id
= ap
->clockid
;
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().
100 pthread_condattr_setpshared(pthread_condattr_t
*attr
, int pshared
)
104 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
105 (pshared
== PTHREAD_PROCESS_PRIVATE
||
106 pshared
== PTHREAD_PROCESS_SHARED
)) {
107 ap
->pshared
= pshared
;
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
)
122 if (attr
!= NULL
&& (ap
= attr
->__pthread_condattrp
) != NULL
&&
124 *pshared
= ap
->pshared
;
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
)
144 type
= PTHREAD_PROCESS_PRIVATE
;
145 clock_id
= CLOCK_REALTIME
;
146 } else if ((ap
= attr
->__pthread_condattrp
) != NULL
) {
148 clock_id
= ap
->clockid
;
153 if (clock_id
!= CLOCK_REALTIME
&& clock_id
!= CLOCK_HIGHRES
)
155 else if ((error
= cond_init((cond_t
*)cond
, type
, NULL
)) == 0)
156 ((cond_t
*)cond
)->cond_clockid
= (uint8_t)clock_id
;