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