]> sourceware.org Git - glibc.git/blame - mach/lock-intern.h
* sysdeps/mach/hurd/Makefile ($(link-rpcuserlibs)): Don't append
[glibc.git] / mach / lock-intern.h
CommitLineData
10dc2a90
UD
1/* Copyright (C) 1994, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
28f540f4 3
10dc2a90
UD
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.
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
12 Library General Public License for more details.
28f540f4 13
10dc2a90
UD
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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4
RM
18
19#ifndef _LOCK_INTERN_H
20#define _LOCK_INTERN_H
21
22#include <machine-lock.h>
23
24#ifndef _EXTERN_INLINE
25#define _EXTERN_INLINE extern __inline
26#endif
27
28
29/* Initialize LOCK. */
30
31_EXTERN_INLINE void
32__spin_lock_init (__spin_lock_t *__lock)
33{
34 *__lock = __SPIN_LOCK_INITIALIZER;
35}
36
37
38/* Lock LOCK, blocking if we can't get it. */
39extern void __spin_lock_solid (__spin_lock_t *__lock);
40
41/* Lock the spin lock LOCK. */
42
43_EXTERN_INLINE void
44__spin_lock (__spin_lock_t *__lock)
45{
46 if (! __spin_try_lock (__lock))
47 __spin_lock_solid (__lock);
48}
49\f
10dc2a90 50/* Name space-clean internal interface to mutex locks.
28f540f4
RM
51
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. */
59
60
61/* Initialize the newly allocated mutex lock LOCK for further use. */
62extern void __mutex_init (void *__lock);
63
64/* Lock LOCK, blocking if we can't get it. */
65extern void __mutex_lock_solid (void *__lock);
66
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. */
69extern void __mutex_unlock_solid (void *__lock);
70
71/* Lock the mutex lock LOCK. */
72
73_EXTERN_INLINE void
74__mutex_lock (void *__lock)
75{
76 if (! __spin_try_lock ((__spin_lock_t *) __lock))
77 __mutex_lock_solid (__lock);
78}
79
80/* Unlock the mutex lock LOCK. */
81
82_EXTERN_INLINE void
83__mutex_unlock (void *__lock)
84{
85 __spin_unlock ((__spin_lock_t *) __lock);
86 __mutex_unlock_solid (__lock);
87}
88
10dc2a90
UD
89
90_EXTERN_INLINE int
91__mutex_trylock (void *__lock)
92{
93 return __spin_try_lock ((__spin_lock_t *) __lock);
94}
95
28f540f4 96#endif /* lock-intern.h */
This page took 0.148225 seconds and 5 git commands to generate.