xref: /illumos-gate/usr/src/lib/libc/port/sys/lwp_rwlock.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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 #include "lint.h"
28 #include <synch.h>
29 #include <time.h>
30 #include <errno.h>
31 #include <sys/syscall.h>
32 
33 #define	SUBSYS_lwp_rwlock_rdlock	0
34 #define	SUBSYS_lwp_rwlock_wrlock	1
35 #define	SUBSYS_lwp_rwlock_tryrdlock	2
36 #define	SUBSYS_lwp_rwlock_trywrlock	3
37 #define	SUBSYS_lwp_rwlock_unlock	4
38 
39 int
40 __lwp_rwlock_rdlock(rwlock_t *rwl, timespec_t *tsp)
41 {
42 	sysret_t rval;
43 	int error;
44 
45 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
46 	    SUBSYS_lwp_rwlock_rdlock, rwl, tsp);
47 	if (error == ERESTART)
48 		error = EINTR;
49 
50 	return (error);
51 }
52 
53 int
54 __lwp_rwlock_wrlock(rwlock_t *rwl, timespec_t *tsp)
55 {
56 	sysret_t rval;
57 	int error;
58 
59 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
60 	    SUBSYS_lwp_rwlock_wrlock, rwl, tsp);
61 	if (error == ERESTART)
62 		error = EINTR;
63 
64 	return (error);
65 }
66 
67 int
68 __lwp_rwlock_tryrdlock(rwlock_t *rwl)
69 {
70 	sysret_t rval;
71 	int error;
72 
73 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
74 	    SUBSYS_lwp_rwlock_tryrdlock, rwl);
75 	if (error == ERESTART)
76 		error = EINTR;
77 
78 	return (error);
79 }
80 
81 int
82 __lwp_rwlock_trywrlock(rwlock_t *rwl)
83 {
84 	sysret_t rval;
85 	int error;
86 
87 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
88 	    SUBSYS_lwp_rwlock_trywrlock, rwl);
89 	if (error == ERESTART)
90 		error = EINTR;
91 
92 	return (error);
93 }
94 
95 int
96 __lwp_rwlock_unlock(rwlock_t *rwl)
97 {
98 	sysret_t rval;
99 	int error;
100 
101 	error = __systemcall(&rval, SYS_lwp_rwlock_sys,
102 	    SUBSYS_lwp_rwlock_unlock, rwl);
103 	if (error == ERESTART)
104 		error = EINTR;
105 
106 	return (error);
107 }
108