Add 4-byte header to messages so that we can have different message types
[glibc/nacl-glibc.git] / mach / lock-intern.h
blob4aaaedc1c05513a3450e8f1040420030340517cb
1 /* Copyright (C) 1994, 1996, 2007 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #ifndef _LOCK_INTERN_H
20 #define _LOCK_INTERN_H
22 #include <sys/cdefs.h>
23 #include <machine-lock.h>
25 #ifndef _EXTERN_INLINE
26 #define _EXTERN_INLINE __extern_inline
27 #endif
30 /* Initialize LOCK. */
32 _EXTERN_INLINE void
33 __spin_lock_init (__spin_lock_t *__lock)
35 *__lock = __SPIN_LOCK_INITIALIZER;
39 /* Lock LOCK, blocking if we can't get it. */
40 extern void __spin_lock_solid (__spin_lock_t *__lock);
42 /* Lock the spin lock LOCK. */
44 _EXTERN_INLINE void
45 __spin_lock (__spin_lock_t *__lock)
47 if (! __spin_try_lock (__lock))
48 __spin_lock_solid (__lock);
51 /* Name space-clean internal interface to mutex locks.
53 Code internal to the C library uses these functions to lock and unlock
54 mutex locks. These locks are of type `struct mutex', defined in
55 <cthreads.h>. The functions here are name space-clean. If the program
56 is linked with the cthreads library, `__mutex_lock_solid' and
57 `__mutex_unlock_solid' will invoke the corresponding cthreads functions
58 to implement real mutex locks. If not, simple stub versions just use
59 spin locks. */
62 /* Initialize the newly allocated mutex lock LOCK for further use. */
63 extern void __mutex_init (void *__lock);
65 /* Lock LOCK, blocking if we can't get it. */
66 extern void __mutex_lock_solid (void *__lock);
68 /* Finish unlocking LOCK, after the spin lock LOCK->held has already been
69 unlocked. This function will wake up any thread waiting on LOCK. */
70 extern void __mutex_unlock_solid (void *__lock);
72 /* Lock the mutex lock LOCK. */
74 _EXTERN_INLINE void
75 __mutex_lock (void *__lock)
77 if (! __spin_try_lock ((__spin_lock_t *) __lock))
78 __mutex_lock_solid (__lock);
81 /* Unlock the mutex lock LOCK. */
83 _EXTERN_INLINE void
84 __mutex_unlock (void *__lock)
86 __spin_unlock ((__spin_lock_t *) __lock);
87 __mutex_unlock_solid (__lock);
91 _EXTERN_INLINE int
92 __mutex_trylock (void *__lock)
94 return __spin_try_lock ((__spin_lock_t *) __lock);
97 #endif /* lock-intern.h */