xref: /titanic_44/usr/src/lib/libc/port/sys/lwp.c (revision 28167c24ba5be8b7c1d05e02d053f4a55cd21cc9)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #pragma weak _private_lwp_mutex_lock = __lwp_mutex_lock
31 #pragma weak _lwp_mutex_lock = __lwp_mutex_lock
32 #pragma weak _lwp_mutex_trylock = __lwp_mutex_trylock
33 #pragma weak _lwp_sema_init = __lwp_sema_init
34 #pragma weak _lwp_sema_wait = __lwp_sema_wait
35 #pragma weak _lwp_suspend = __lwp_suspend
36 #if defined(__i386) || defined(__amd64)
37 #pragma weak _lwp_private = __lwp_private
38 #endif	/* __i386 || __amd64 */
39 
40 #include "synonyms.h"
41 #include "thr_uberdata.h"
42 #include <sys/types.h>
43 #include <sys/time.h>
44 #include <errno.h>
45 #include <synch.h>
46 #include <sys/synch32.h>
47 #include <sys/lwp.h>
48 
49 extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *);
50 extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
51 
52 int
53 _lwp_mutex_lock(mutex_t *mp)
54 {
55 	if (set_lock_byte(&mp->mutex_lockw) == 0)
56 		return (0);
57 	return (___lwp_mutex_timedlock(mp, NULL));
58 }
59 
60 int
61 _lwp_mutex_trylock(mutex_t *mp)
62 {
63 	if (set_lock_byte(&mp->mutex_lockw) == 0)
64 		return (0);
65 	return (EBUSY);
66 }
67 
68 int
69 _lwp_sema_init(lwp_sema_t *sp, int count)
70 {
71 	sp->sema_count = count;
72 	sp->sema_waiters = 0;
73 	sp->type = USYNC_PROCESS;
74 	return (0);
75 }
76 
77 int
78 _lwp_sema_wait(lwp_sema_t *sp)
79 {
80 	return (___lwp_sema_timedwait(sp, NULL, 0));
81 }
82 
83 #if defined(__x86)
84 int
85 _lwp_private(int cmd, int which, void *sbase)
86 {
87 	extern int ___lwp_private(int, int, void *);
88 	return (___lwp_private(cmd, which, sbase));
89 }
90 #endif	/* __x86 */
91 
92 int
93 _lwp_suspend(lwpid_t lwpid)
94 {
95 	extern int ___lwp_suspend(lwpid_t);
96 	return (___lwp_suspend(lwpid));
97 }
98