xref: /onnv-gate/usr/src/lib/libc/port/sys/lwp_cond.c (revision 10887:25ca697b9a84)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56812Sraf  * Common Development and Distribution License (the "License").
66812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216812Sraf 
220Sstevel@tonic-gate /*
23*10887SRoger.Faulkner@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
276812Sraf #include "lint.h"
28*10887SRoger.Faulkner@Sun.COM #include "thr_uberdata.h"
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <time.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include <synch.h>
330Sstevel@tonic-gate #include <sys/synch32.h>
340Sstevel@tonic-gate #include <pthread.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate int
_lwp_cond_wait(cond_t * cv,mutex_t * mp)370Sstevel@tonic-gate _lwp_cond_wait(cond_t *cv, mutex_t *mp)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	int error;
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 	error = ___lwp_cond_wait(cv, mp, NULL, 0);
420Sstevel@tonic-gate 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
43*10887SRoger.Faulkner@Sun.COM 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
440Sstevel@tonic-gate 	else
450Sstevel@tonic-gate 		(void) _lwp_mutex_lock(mp);
460Sstevel@tonic-gate 	return (error);
470Sstevel@tonic-gate }
480Sstevel@tonic-gate 
490Sstevel@tonic-gate int
_lwp_cond_reltimedwait(cond_t * cv,mutex_t * mp,timespec_t * relts)500Sstevel@tonic-gate _lwp_cond_reltimedwait(cond_t *cv, mutex_t *mp, timespec_t *relts)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate 	int error;
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 	if (relts != NULL &&
550Sstevel@tonic-gate 	    (relts->tv_sec < 0 || (ulong_t)relts->tv_nsec >= NANOSEC))
560Sstevel@tonic-gate 		return (EINVAL);
570Sstevel@tonic-gate 	error = ___lwp_cond_wait(cv, mp, relts, 0);
580Sstevel@tonic-gate 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
59*10887SRoger.Faulkner@Sun.COM 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
600Sstevel@tonic-gate 	else
610Sstevel@tonic-gate 		(void) _lwp_mutex_lock(mp);
620Sstevel@tonic-gate 	return (error);
630Sstevel@tonic-gate }
640Sstevel@tonic-gate 
650Sstevel@tonic-gate int
_lwp_cond_timedwait(cond_t * cv,mutex_t * mp,timespec_t * absts)660Sstevel@tonic-gate _lwp_cond_timedwait(cond_t *cv, mutex_t *mp, timespec_t *absts)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate 	extern void abstime_to_reltime(clockid_t,
696812Sraf 	    const timespec_t *, timespec_t *);
700Sstevel@tonic-gate 	timespec_t tslocal;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	abstime_to_reltime(CLOCK_REALTIME, absts, &tslocal);
730Sstevel@tonic-gate 	return (_lwp_cond_reltimedwait(cv, mp, &tslocal));
740Sstevel@tonic-gate }
75