xref: /titanic_44/usr/src/lib/libc/port/sys/lwp.c (revision 4a634bb80136cc001d14ab96addd9915105e5223)
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 #pragma weak _lwp_mutex_lock = __lwp_mutex_lock
30 #pragma weak _lwp_mutex_trylock = __lwp_mutex_trylock
31 #pragma weak _lwp_sema_init = __lwp_sema_init
32 #pragma weak _lwp_sema_wait = __lwp_sema_wait
33 #pragma weak _lwp_suspend = __lwp_suspend
34 #if defined(__i386) || defined(__amd64)
35 #pragma weak _lwp_private = __lwp_private
36 #endif	/* __i386 || __amd64 */
37 
38 #include "synonyms.h"
39 #include "thr_uberdata.h"
40 #include <sys/types.h>
41 #include <sys/time.h>
42 #include <errno.h>
43 #include <synch.h>
44 #include <sys/synch32.h>
45 #include <sys/lwp.h>
46 
47 extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *);
48 extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
49 
50 int
51 _lwp_mutex_lock(mutex_t *mp)
52 {
53 	if (set_lock_byte(&mp->mutex_lockw) == 0)
54 		return (0);
55 	return (___lwp_mutex_timedlock(mp, NULL));
56 }
57 
58 int
59 _lwp_mutex_trylock(mutex_t *mp)
60 {
61 	if (set_lock_byte(&mp->mutex_lockw) == 0)
62 		return (0);
63 	return (EBUSY);
64 }
65 
66 int
67 _lwp_sema_init(lwp_sema_t *sp, int count)
68 {
69 	sp->sema_count = count;
70 	sp->sema_waiters = 0;
71 	sp->type = USYNC_PROCESS;
72 	return (0);
73 }
74 
75 int
76 _lwp_sema_wait(lwp_sema_t *sp)
77 {
78 	return (___lwp_sema_timedwait(sp, NULL, 0));
79 }
80 
81 #if defined(__x86)
82 int
83 _lwp_private(int cmd, int which, void *sbase)
84 {
85 	extern int ___lwp_private(int, int, void *);
86 	return (___lwp_private(cmd, which, sbase));
87 }
88 #endif	/* __x86 */
89 
90 int
91 _lwp_suspend(lwpid_t lwpid)
92 {
93 	extern int ___lwp_suspend(lwpid_t);
94 	return (___lwp_suspend(lwpid));
95 }
96