xref: /onnv-gate/usr/src/lib/libc/port/sys/lwp.c (revision 10887:25ca697b9a84)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56515Sraf  * Common Development and Distribution License (the "License").
66515Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211016Sraf 
220Sstevel@tonic-gate /*
23*10887SRoger.Faulkner@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
276812Sraf #include "lint.h"
281016Sraf #include "thr_uberdata.h"
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/time.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include <synch.h>
330Sstevel@tonic-gate #include <sys/synch32.h>
340Sstevel@tonic-gate #include <sys/lwp.h>
350Sstevel@tonic-gate 
360Sstevel@tonic-gate int
_lwp_mutex_lock(mutex_t * mp)370Sstevel@tonic-gate _lwp_mutex_lock(mutex_t *mp)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate 	if (set_lock_byte(&mp->mutex_lockw) == 0)
400Sstevel@tonic-gate 		return (0);
41*10887SRoger.Faulkner@Sun.COM 	return (___lwp_mutex_timedlock(mp, NULL, NULL));
420Sstevel@tonic-gate }
430Sstevel@tonic-gate 
440Sstevel@tonic-gate int
_lwp_mutex_trylock(mutex_t * mp)450Sstevel@tonic-gate _lwp_mutex_trylock(mutex_t *mp)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate 	if (set_lock_byte(&mp->mutex_lockw) == 0)
480Sstevel@tonic-gate 		return (0);
490Sstevel@tonic-gate 	return (EBUSY);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate 
520Sstevel@tonic-gate int
_lwp_sema_init(lwp_sema_t * sp,int count)530Sstevel@tonic-gate _lwp_sema_init(lwp_sema_t *sp, int count)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate 	sp->sema_count = count;
560Sstevel@tonic-gate 	sp->sema_waiters = 0;
570Sstevel@tonic-gate 	sp->type = USYNC_PROCESS;
580Sstevel@tonic-gate 	return (0);
590Sstevel@tonic-gate }
600Sstevel@tonic-gate 
610Sstevel@tonic-gate int
_lwp_sema_wait(lwp_sema_t * sp)620Sstevel@tonic-gate _lwp_sema_wait(lwp_sema_t *sp)
630Sstevel@tonic-gate {
640Sstevel@tonic-gate 	return (___lwp_sema_timedwait(sp, NULL, 0));
650Sstevel@tonic-gate }
660Sstevel@tonic-gate 
670Sstevel@tonic-gate int
_lwp_suspend(lwpid_t lwpid)680Sstevel@tonic-gate _lwp_suspend(lwpid_t lwpid)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate 	extern int ___lwp_suspend(lwpid_t);
710Sstevel@tonic-gate 	return (___lwp_suspend(lwpid));
720Sstevel@tonic-gate }
73