Sun May 12 11:16:58 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc/history.git] / mach / lock-intern.h
blob9c6bab5ae238886be7a459fdbd59dca72c2da6c1
1 /* Copyright (C) 1994 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 Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #ifndef _LOCK_INTERN_H
20 #define _LOCK_INTERN_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);
89 #endif /* lock-intern.h */