xref: /illumos-gate/usr/src/lib/libc/port/sys/lwp_cond.c (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include "lint.h"
28 #include "thr_uberdata.h"
29 #include <sys/types.h>
30 #include <time.h>
31 #include <errno.h>
32 #include <synch.h>
33 #include <sys/synch32.h>
34 #include <pthread.h>
35 
36 int
37 _lwp_cond_wait(cond_t *cv, mutex_t *mp)
38 {
39 	int error;
40 
41 	error = ___lwp_cond_wait(cv, mp, NULL, 0);
42 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
43 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
44 	else
45 		(void) _lwp_mutex_lock(mp);
46 	return (error);
47 }
48 
49 int
50 _lwp_cond_reltimedwait(cond_t *cv, mutex_t *mp, timespec_t *relts)
51 {
52 	int error;
53 
54 	if (relts != NULL &&
55 	    (relts->tv_sec < 0 || (ulong_t)relts->tv_nsec >= NANOSEC))
56 		return (EINVAL);
57 	error = ___lwp_cond_wait(cv, mp, relts, 0);
58 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
59 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
60 	else
61 		(void) _lwp_mutex_lock(mp);
62 	return (error);
63 }
64 
65 int
66 _lwp_cond_timedwait(cond_t *cv, mutex_t *mp, timespec_t *absts)
67 {
68 	extern void abstime_to_reltime(clockid_t,
69 	    const timespec_t *, timespec_t *);
70 	timespec_t tslocal;
71 
72 	abstime_to_reltime(CLOCK_REALTIME, absts, &tslocal);
73 	return (_lwp_cond_reltimedwait(cv, mp, &tslocal));
74 }
75