xref: /onnv-gate/usr/src/lib/libc/port/sys/lwp_rwlock.c (revision 6812:febeba71273d)
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
54570Sraf  * Common Development and Distribution License (the "License").
64570Sraf  * 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  */
214570Sraf 
220Sstevel@tonic-gate /*
235924Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include <synch.h>
310Sstevel@tonic-gate #include <time.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate #include <sys/syscall.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #define	SUBSYS_lwp_rwlock_rdlock	0
360Sstevel@tonic-gate #define	SUBSYS_lwp_rwlock_wrlock	1
370Sstevel@tonic-gate #define	SUBSYS_lwp_rwlock_tryrdlock	2
380Sstevel@tonic-gate #define	SUBSYS_lwp_rwlock_trywrlock	3
390Sstevel@tonic-gate #define	SUBSYS_lwp_rwlock_unlock	4
400Sstevel@tonic-gate 
410Sstevel@tonic-gate int
__lwp_rwlock_rdlock(rwlock_t * rwl,timespec_t * tsp)420Sstevel@tonic-gate __lwp_rwlock_rdlock(rwlock_t *rwl, timespec_t *tsp)
430Sstevel@tonic-gate {
445924Sraf 	sysret_t rval;
455924Sraf 	int error;
465924Sraf 
475924Sraf 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
485924Sraf 	    SUBSYS_lwp_rwlock_rdlock, rwl, tsp);
495924Sraf 	if (error == ERESTART)
505924Sraf 		error = EINTR;
515924Sraf 
525924Sraf 	return (error);
530Sstevel@tonic-gate }
540Sstevel@tonic-gate 
550Sstevel@tonic-gate int
__lwp_rwlock_wrlock(rwlock_t * rwl,timespec_t * tsp)560Sstevel@tonic-gate __lwp_rwlock_wrlock(rwlock_t *rwl, timespec_t *tsp)
570Sstevel@tonic-gate {
585924Sraf 	sysret_t rval;
595924Sraf 	int error;
605924Sraf 
615924Sraf 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
625924Sraf 	    SUBSYS_lwp_rwlock_wrlock, rwl, tsp);
635924Sraf 	if (error == ERESTART)
645924Sraf 		error = EINTR;
655924Sraf 
665924Sraf 	return (error);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate 
690Sstevel@tonic-gate int
__lwp_rwlock_tryrdlock(rwlock_t * rwl)700Sstevel@tonic-gate __lwp_rwlock_tryrdlock(rwlock_t *rwl)
710Sstevel@tonic-gate {
725924Sraf 	sysret_t rval;
735924Sraf 	int error;
745924Sraf 
755924Sraf 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
765924Sraf 	    SUBSYS_lwp_rwlock_tryrdlock, rwl);
775924Sraf 	if (error == ERESTART)
785924Sraf 		error = EINTR;
795924Sraf 
805924Sraf 	return (error);
810Sstevel@tonic-gate }
820Sstevel@tonic-gate 
830Sstevel@tonic-gate int
__lwp_rwlock_trywrlock(rwlock_t * rwl)840Sstevel@tonic-gate __lwp_rwlock_trywrlock(rwlock_t *rwl)
850Sstevel@tonic-gate {
865924Sraf 	sysret_t rval;
875924Sraf 	int error;
885924Sraf 
895924Sraf 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
905924Sraf 	    SUBSYS_lwp_rwlock_trywrlock, rwl);
915924Sraf 	if (error == ERESTART)
925924Sraf 		error = EINTR;
935924Sraf 
945924Sraf 	return (error);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate int
__lwp_rwlock_unlock(rwlock_t * rwl)980Sstevel@tonic-gate __lwp_rwlock_unlock(rwlock_t *rwl)
990Sstevel@tonic-gate {
1005924Sraf 	sysret_t rval;
1015924Sraf 	int error;
1025924Sraf 
1035924Sraf 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
1045924Sraf 	    SUBSYS_lwp_rwlock_unlock, rwl);
1055924Sraf 	if (error == ERESTART)
1065924Sraf 		error = EINTR;
1075924Sraf 
1085924Sraf 	return (error);
1090Sstevel@tonic-gate }
110