delete ksh checks
[glibc.git] / mach / lock-intern.h
blobb85ed736750f5f3fd290665ea63e2049c65d884b
1 /* Copyright (C) 1994-2014 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 <http://www.gnu.org/licenses/>. */
18 #ifndef _LOCK_INTERN_H
19 #define _LOCK_INTERN_H
21 #include <sys/cdefs.h>
22 #include <machine-lock.h>
24 #ifndef _EXTERN_INLINE
25 #define _EXTERN_INLINE __extern_inline
26 #endif
29 /* Initialize LOCK. */
31 _EXTERN_INLINE void
32 __spin_lock_init (__spin_lock_t *__lock)
34 *__lock = __SPIN_LOCK_INITIALIZER;
38 /* Lock LOCK, blocking if we can't get it. */
39 extern void __spin_lock_solid (__spin_lock_t *__lock);
41 /* Lock the spin lock LOCK. */
43 _EXTERN_INLINE void
44 __spin_lock (__spin_lock_t *__lock)
46 if (! __spin_try_lock (__lock))
47 __spin_lock_solid (__lock);
50 /* Name space-clean internal interface to mutex locks.
52 Code internal to the C library uses these functions to lock and unlock
53 mutex locks. These locks are of type `struct mutex', defined in
54 <cthreads.h>. The functions here are name space-clean. If the program
55 is linked with the cthreads library, `__mutex_lock_solid' and
56 `__mutex_unlock_solid' will invoke the corresponding cthreads functions
57 to implement real mutex locks. If not, simple stub versions just use
58 spin locks. */
61 /* Initialize the newly allocated mutex lock LOCK for further use. */
62 extern void __mutex_init (void *__lock);
64 /* Lock LOCK, blocking if we can't get it. */
65 extern void __mutex_lock_solid (void *__lock);
67 /* Finish unlocking LOCK, after the spin lock LOCK->held has already been
68 unlocked. This function will wake up any thread waiting on LOCK. */
69 extern void __mutex_unlock_solid (void *__lock);
71 /* Lock the mutex lock LOCK. */
73 _EXTERN_INLINE void
74 __mutex_lock (void *__lock)
76 if (! __spin_try_lock ((__spin_lock_t *) __lock))
77 __mutex_lock_solid (__lock);
80 /* Unlock the mutex lock LOCK. */
82 _EXTERN_INLINE void
83 __mutex_unlock (void *__lock)
85 __spin_unlock ((__spin_lock_t *) __lock);
86 __mutex_unlock_solid (__lock);
90 _EXTERN_INLINE int
91 __mutex_trylock (void *__lock)
93 return __spin_try_lock ((__spin_lock_t *) __lock);
96 #endif /* lock-intern.h */