1 /* Copyright (C) 1994-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _LOCK_INTERN_H
19 #define _LOCK_INTERN_H
21 #include <sys/cdefs.h>
22 #if defined __USE_EXTERN_INLINES && defined _LIBC
23 # include <lowlevellock.h>
26 #ifndef _EXTERN_INLINE
27 #define _EXTERN_INLINE __extern_inline
30 /* The type of a spin lock variable. */
31 typedef unsigned int __spin_lock_t
;
33 /* Static initializer for spinlocks. */
34 #define __SPIN_LOCK_INITIALIZER LLL_LOCK_INITIALIZER
36 /* Initialize LOCK. */
38 extern void __spin_lock_init (__spin_lock_t
*__lock
);
40 #if defined __USE_EXTERN_INLINES && defined _LIBC
42 __spin_lock_init (__spin_lock_t
*__lock
)
44 *__lock
= __SPIN_LOCK_INITIALIZER
;
49 /* Lock LOCK, blocking if we can't get it. */
50 extern void __spin_lock_solid (__spin_lock_t
*__lock
);
52 /* Lock the spin lock LOCK. */
54 extern void __spin_lock (__spin_lock_t
*__lock
);
56 #if defined __USE_EXTERN_INLINES && defined _LIBC
58 __spin_lock (__spin_lock_t
*__lock
)
60 __lll_lock (__lock
, 0);
65 extern void __spin_unlock (__spin_lock_t
*__lock
);
67 #if defined __USE_EXTERN_INLINES && defined _LIBC
69 __spin_unlock (__spin_lock_t
*__lock
)
71 __lll_unlock (__lock
, 0);
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
);
78 #if defined __USE_EXTERN_INLINES && defined _LIBC
80 __spin_try_lock (__spin_lock_t
*__lock
)
82 return (__lll_trylock (__lock
) == 0);
86 /* Return nonzero if LOCK is locked. */
87 extern int __spin_lock_locked (__spin_lock_t
*__lock
);
89 #if defined __USE_EXTERN_INLINES && defined _LIBC
91 __spin_lock_locked (__spin_lock_t
*__lock
)
93 return (*(volatile __spin_lock_t
*)__lock
!= 0);
97 /* Name space-clean internal interface to mutex locks. */
100 __spin_lock_t __lock
;
102 void *__head
, *__tail
;
106 #define MUTEX_INITIALIZER { __SPIN_LOCK_INITIALIZER }
108 /* Initialize the newly allocated mutex lock LOCK for further use. */
109 extern void __mutex_init (void *__lock
);
111 /* Lock the mutex lock LOCK. */
113 extern void __mutex_lock (void *__lock
);
115 #if defined __USE_EXTERN_INLINES && defined _LIBC
117 __mutex_lock (void *__lock
)
119 __spin_lock ((__spin_lock_t
*)__lock
);
123 /* Unlock the mutex lock LOCK. */
125 extern void __mutex_unlock (void *__lock
);
127 #if defined __USE_EXTERN_INLINES && defined _LIBC
129 __mutex_unlock (void *__lock
)
131 __spin_unlock ((__spin_lock_t
*)__lock
);
136 extern int __mutex_trylock (void *__lock
);
138 #if defined __USE_EXTERN_INLINES && defined _LIBC
140 __mutex_trylock (void *__lock
)
142 return (__spin_try_lock ((__spin_lock_t
*)__lock
));
146 #endif /* lock-intern.h */