import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / sys / lwp_cond.c
blobb9bac4638169c277f600a45bacbdb686e24663fe
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
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>
36 int
37 _lwp_cond_wait(cond_t *cv, mutex_t *mp)
39 int error;
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);
49 int
50 _lwp_cond_reltimedwait(cond_t *cv, mutex_t *mp, timespec_t *relts)
52 int error;
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);
65 int
66 _lwp_cond_timedwait(cond_t *cv, mutex_t *mp, timespec_t *absts)
68 extern void abstime_to_reltime(clockid_t,
69 const timespec_t *, timespec_t *);
70 timespec_t tslocal;
72 abstime_to_reltime(CLOCK_REALTIME, absts, &tslocal);
73 return (_lwp_cond_reltimedwait(cv, mp, &tslocal));