xref: /titanic_44/usr/src/lib/libc/port/sys/lwp.c (revision c28749e97052f09388969427adf7df641cdcdc22)
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  * Copyright 2004 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 _private_lwp_mutex_lock = __lwp_mutex_lock
30 #pragma weak _lwp_mutex_lock = __lwp_mutex_lock
31 #pragma weak _lwp_mutex_trylock = __lwp_mutex_trylock
32 #pragma weak _lwp_sema_init = __lwp_sema_init
33 #pragma weak _lwp_sema_wait = __lwp_sema_wait
34 #pragma weak _lwp_suspend = __lwp_suspend
35 #if defined(__i386) || defined(__amd64)
36 #pragma weak _lwp_private = __lwp_private
37 #endif	/* __i386 || __amd64 */
38 
39 #include "synonyms.h"
40 #include "mtlib.h"
41 #include <sys/types.h>
42 #include <sys/time.h>
43 #include <errno.h>
44 #include <synch.h>
45 #include <sys/synch32.h>
46 #include <sys/lwp.h>
47 
48 extern int ___lwp_mutex_timedlock(mutex_t *, timespec_t *);
49 extern int ___lwp_sema_timedwait(lwp_sema_t *, timespec_t *, int);
50 extern int set_lock_byte(volatile uint8_t *);
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(__i386) || defined(__amd64)
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	/* __i386 || __amd64 */
91 
92 int
93 _lwp_suspend(lwpid_t lwpid)
94 {
95 	extern int ___lwp_suspend(lwpid_t);
96 	return (___lwp_suspend(lwpid));
97 }
98 
99 void
100 _halt(void)
101 {
102 	/*LINTED*/
103 	while (1)
104 		continue;
105 }
106