]>
Commit | Line | Data |
---|---|---|
04277e02 | 1 | /* Copyright (C) 1994-2019 Free Software Foundation, Inc. |
10dc2a90 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
10dc2a90 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 8 | |
10dc2a90 UD |
9 | The GNU C Library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 RM |
17 | |
18 | #ifndef _LOCK_INTERN_H | |
19 | #define _LOCK_INTERN_H | |
20 | ||
610903b0 | 21 | #include <sys/cdefs.h> |
fb4cc8a0 AA |
22 | #if defined __USE_EXTERN_INLINES && defined _LIBC |
23 | # include <lowlevellock.h> | |
24 | #endif | |
28f540f4 RM |
25 | |
26 | #ifndef _EXTERN_INLINE | |
b037a293 | 27 | #define _EXTERN_INLINE __extern_inline |
28f540f4 RM |
28 | #endif |
29 | ||
fb4cc8a0 AA |
30 | /* The type of a spin lock variable. */ |
31 | typedef unsigned int __spin_lock_t; | |
32 | ||
33 | /* Static initializer for spinlocks. */ | |
34 | #define __SPIN_LOCK_INITIALIZER LLL_INITIALIZER | |
28f540f4 RM |
35 | |
36 | /* Initialize LOCK. */ | |
37 | ||
28f6186f ST |
38 | extern void __spin_lock_init (__spin_lock_t *__lock); |
39 | ||
40 | #if defined __USE_EXTERN_INLINES && defined _LIBC | |
28f540f4 RM |
41 | _EXTERN_INLINE void |
42 | __spin_lock_init (__spin_lock_t *__lock) | |
43 | { | |
44 | *__lock = __SPIN_LOCK_INITIALIZER; | |
45 | } | |
28f6186f | 46 | #endif |
28f540f4 RM |
47 | |
48 | ||
49 | /* Lock LOCK, blocking if we can't get it. */ | |
50 | extern void __spin_lock_solid (__spin_lock_t *__lock); | |
51 | ||
52 | /* Lock the spin lock LOCK. */ | |
53 | ||
28f6186f ST |
54 | extern void __spin_lock (__spin_lock_t *__lock); |
55 | ||
56 | #if defined __USE_EXTERN_INLINES && defined _LIBC | |
28f540f4 RM |
57 | _EXTERN_INLINE void |
58 | __spin_lock (__spin_lock_t *__lock) | |
59 | { | |
fb4cc8a0 | 60 | lll_lock (__lock, 0); |
28f540f4 | 61 | } |
28f6186f | 62 | #endif |
28f540f4 | 63 | |
fb4cc8a0 AA |
64 | /* Unlock LOCK. */ |
65 | extern void __spin_unlock (__spin_lock_t *__lock); | |
28f540f4 | 66 | |
fb4cc8a0 AA |
67 | #if defined __USE_EXTERN_INLINES && defined _LIBC |
68 | _EXTERN_INLINE void | |
69 | __spin_unlock (__spin_lock_t *__lock) | |
70 | { | |
71 | lll_unlock (__lock, 0); | |
72 | } | |
73 | #endif | |
28f540f4 | 74 | |
fb4cc8a0 AA |
75 | /* Try to lock LOCK; return nonzero if we locked it, zero if another has. */ |
76 | extern int __spin_try_lock (__spin_lock_t *__lock); | |
28f540f4 | 77 | |
fb4cc8a0 AA |
78 | #if defined __USE_EXTERN_INLINES && defined _LIBC |
79 | _EXTERN_INLINE int | |
80 | __spin_try_lock (__spin_lock_t *__lock) | |
81 | { | |
82 | return (lll_trylock (__lock) == 0); | |
83 | } | |
84 | #endif | |
85 | ||
86 | /* Return nonzero if LOCK is locked. */ | |
87 | extern int __spin_lock_locked (__spin_lock_t *__lock); | |
28f540f4 | 88 | |
fb4cc8a0 AA |
89 | #if defined __USE_EXTERN_INLINES && defined _LIBC |
90 | _EXTERN_INLINE int | |
91 | __spin_lock_locked (__spin_lock_t *__lock) | |
92 | { | |
93 | return (*(volatile __spin_lock_t *)__lock != 0); | |
94 | } | |
95 | #endif | |
96 | \f | |
97 | /* Name space-clean internal interface to mutex locks. */ | |
98 | ||
99 | /* Initialize the newly allocated mutex lock LOCK for further use. */ | |
100 | extern void __mutex_init (void *__lock); | |
28f540f4 RM |
101 | |
102 | /* Lock the mutex lock LOCK. */ | |
103 | ||
28f6186f ST |
104 | extern void __mutex_lock (void *__lock); |
105 | ||
106 | #if defined __USE_EXTERN_INLINES && defined _LIBC | |
28f540f4 RM |
107 | _EXTERN_INLINE void |
108 | __mutex_lock (void *__lock) | |
109 | { | |
fb4cc8a0 | 110 | __spin_lock ((__spin_lock_t *)__lock); |
28f540f4 | 111 | } |
28f6186f | 112 | #endif |
28f540f4 RM |
113 | |
114 | /* Unlock the mutex lock LOCK. */ | |
115 | ||
28f6186f ST |
116 | extern void __mutex_unlock (void *__lock); |
117 | ||
118 | #if defined __USE_EXTERN_INLINES && defined _LIBC | |
28f540f4 RM |
119 | _EXTERN_INLINE void |
120 | __mutex_unlock (void *__lock) | |
121 | { | |
fb4cc8a0 | 122 | __spin_unlock ((__spin_lock_t *)__lock); |
28f540f4 | 123 | } |
28f6186f | 124 | #endif |
28f540f4 | 125 | |
10dc2a90 | 126 | |
28f6186f ST |
127 | extern int __mutex_trylock (void *__lock); |
128 | ||
129 | #if defined __USE_EXTERN_INLINES && defined _LIBC | |
10dc2a90 UD |
130 | _EXTERN_INLINE int |
131 | __mutex_trylock (void *__lock) | |
132 | { | |
fb4cc8a0 | 133 | return (__spin_try_lock ((__spin_lock_t *)__lock)); |
10dc2a90 | 134 | } |
28f6186f | 135 | #endif |
10dc2a90 | 136 | |
28f540f4 | 137 | #endif /* lock-intern.h */ |