xref: /illumos-gate/usr/src/lib/libc/port/sys/lwp_cond.c (revision db94676f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*db94676fSRoger A. Faulkner  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277257d1b4Sraf #include "lint.h"
28*db94676fSRoger A. Faulkner #include "thr_uberdata.h"
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <time.h>
317c478bd9Sstevel@tonic-gate #include <errno.h>
327c478bd9Sstevel@tonic-gate #include <synch.h>
337c478bd9Sstevel@tonic-gate #include <sys/synch32.h>
347c478bd9Sstevel@tonic-gate #include <pthread.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate int
_lwp_cond_wait(cond_t * cv,mutex_t * mp)377c478bd9Sstevel@tonic-gate _lwp_cond_wait(cond_t *cv, mutex_t *mp)
387c478bd9Sstevel@tonic-gate {
397c478bd9Sstevel@tonic-gate 	int error;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 	error = ___lwp_cond_wait(cv, mp, NULL, 0);
427c478bd9Sstevel@tonic-gate 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
43*db94676fSRoger A. Faulkner 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
447c478bd9Sstevel@tonic-gate 	else
457c478bd9Sstevel@tonic-gate 		(void) _lwp_mutex_lock(mp);
467c478bd9Sstevel@tonic-gate 	return (error);
477c478bd9Sstevel@tonic-gate }
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate int
_lwp_cond_reltimedwait(cond_t * cv,mutex_t * mp,timespec_t * relts)507c478bd9Sstevel@tonic-gate _lwp_cond_reltimedwait(cond_t *cv, mutex_t *mp, timespec_t *relts)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate 	int error;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate 	if (relts != NULL &&
557c478bd9Sstevel@tonic-gate 	    (relts->tv_sec < 0 || (ulong_t)relts->tv_nsec >= NANOSEC))
567c478bd9Sstevel@tonic-gate 		return (EINVAL);
577c478bd9Sstevel@tonic-gate 	error = ___lwp_cond_wait(cv, mp, relts, 0);
587c478bd9Sstevel@tonic-gate 	if (mp->mutex_type & (PTHREAD_PRIO_INHERIT|PTHREAD_PRIO_PROTECT))
59*db94676fSRoger A. Faulkner 		(void) ___lwp_mutex_timedlock(mp, NULL, NULL);
607c478bd9Sstevel@tonic-gate 	else
617c478bd9Sstevel@tonic-gate 		(void) _lwp_mutex_lock(mp);
627c478bd9Sstevel@tonic-gate 	return (error);
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate int
_lwp_cond_timedwait(cond_t * cv,mutex_t * mp,timespec_t * absts)667c478bd9Sstevel@tonic-gate _lwp_cond_timedwait(cond_t *cv, mutex_t *mp, timespec_t *absts)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 	extern void abstime_to_reltime(clockid_t,
697257d1b4Sraf 	    const timespec_t *, timespec_t *);
707c478bd9Sstevel@tonic-gate 	timespec_t tslocal;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	abstime_to_reltime(CLOCK_REALTIME, absts, &tslocal);
737c478bd9Sstevel@tonic-gate 	return (_lwp_cond_reltimedwait(cv, mp, &tslocal));
747c478bd9Sstevel@tonic-gate }
75