xref: /titanic_41/usr/src/lib/libc/port/sys/lwp.c (revision 571575105382b90dc07db52b51d687862849dd05)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "lint.h"
30 #include "thr_uberdata.h"
31 #include <sys/types.h>
32 #include <sys/time.h>
33 #include <errno.h>
34 #include <synch.h>
35 #include <sys/synch32.h>
36 #include <sys/lwp.h>
37 
38 extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *);
39 extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
40 
41 int
42 _lwp_mutex_lock(mutex_t *mp)
43 {
44 	if (set_lock_byte(&mp->mutex_lockw) == 0)
45 		return (0);
46 	return (___lwp_mutex_timedlock(mp, NULL));
47 }
48 
49 int
50 _lwp_mutex_trylock(mutex_t *mp)
51 {
52 	if (set_lock_byte(&mp->mutex_lockw) == 0)
53 		return (0);
54 	return (EBUSY);
55 }
56 
57 int
58 _lwp_sema_init(lwp_sema_t *sp, int count)
59 {
60 	sp->sema_count = count;
61 	sp->sema_waiters = 0;
62 	sp->type = USYNC_PROCESS;
63 	return (0);
64 }
65 
66 int
67 _lwp_sema_wait(lwp_sema_t *sp)
68 {
69 	return (___lwp_sema_timedwait(sp, NULL, 0));
70 }
71 
72 int
73 _lwp_suspend(lwpid_t lwpid)
74 {
75 	extern int ___lwp_suspend(lwpid_t);
76 	return (___lwp_suspend(lwpid));
77 }
78