]> err.no Git - linux-2.6/blob - include/linux/rwsem.h
Merge git://oss.sgi.com:8090/xfs-2.6
[linux-2.6] / include / linux / rwsem.h
1 /* rwsem.h: R/W semaphores, public interface
2  *
3  * Written by David Howells (dhowells@redhat.com).
4  * Derived from asm-i386/semaphore.h
5  */
6
7 #ifndef _LINUX_RWSEM_H
8 #define _LINUX_RWSEM_H
9
10 #include <linux/linkage.h>
11
12 #define RWSEM_DEBUG 0
13
14 #ifdef __KERNEL__
15
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <asm/system.h>
19 #include <asm/atomic.h>
20
21 struct rw_semaphore;
22
23 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
24 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
25 #else
26 #include <asm/rwsem.h> /* use an arch-specific implementation */
27 #endif
28
29 #ifndef rwsemtrace
30 #if RWSEM_DEBUG
31 extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
32 #else
33 #define rwsemtrace(SEM,FMT)
34 #endif
35 #endif
36
37 /*
38  * lock for reading
39  */
40 static inline void down_read(struct rw_semaphore *sem)
41 {
42         might_sleep();
43         rwsemtrace(sem,"Entering down_read");
44         __down_read(sem);
45         rwsemtrace(sem,"Leaving down_read");
46 }
47
48 /*
49  * trylock for reading -- returns 1 if successful, 0 if contention
50  */
51 static inline int down_read_trylock(struct rw_semaphore *sem)
52 {
53         int ret;
54         rwsemtrace(sem,"Entering down_read_trylock");
55         ret = __down_read_trylock(sem);
56         rwsemtrace(sem,"Leaving down_read_trylock");
57         return ret;
58 }
59
60 /*
61  * lock for writing
62  */
63 static inline void down_write(struct rw_semaphore *sem)
64 {
65         might_sleep();
66         rwsemtrace(sem,"Entering down_write");
67         __down_write(sem);
68         rwsemtrace(sem,"Leaving down_write");
69 }
70
71 /*
72  * trylock for writing -- returns 1 if successful, 0 if contention
73  */
74 static inline int down_write_trylock(struct rw_semaphore *sem)
75 {
76         int ret;
77         rwsemtrace(sem,"Entering down_write_trylock");
78         ret = __down_write_trylock(sem);
79         rwsemtrace(sem,"Leaving down_write_trylock");
80         return ret;
81 }
82
83 /*
84  * release a read lock
85  */
86 static inline void up_read(struct rw_semaphore *sem)
87 {
88         rwsemtrace(sem,"Entering up_read");
89         __up_read(sem);
90         rwsemtrace(sem,"Leaving up_read");
91 }
92
93 /*
94  * release a write lock
95  */
96 static inline void up_write(struct rw_semaphore *sem)
97 {
98         rwsemtrace(sem,"Entering up_write");
99         __up_write(sem);
100         rwsemtrace(sem,"Leaving up_write");
101 }
102
103 /*
104  * downgrade write lock to read lock
105  */
106 static inline void downgrade_write(struct rw_semaphore *sem)
107 {
108         rwsemtrace(sem,"Entering downgrade_write");
109         __downgrade_write(sem);
110         rwsemtrace(sem,"Leaving downgrade_write");
111 }
112
113 #endif /* __KERNEL__ */
114 #endif /* _LINUX_RWSEM_H */