93581534b915129b36eb1369471334628103e209
[sfrench/cifs-2.6.git] / 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 #ifdef __KERNEL__
13
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <asm/system.h>
17 #include <asm/atomic.h>
18
19 struct rw_semaphore;
20
21 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
22 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
23 #else
24 #include <asm/rwsem.h> /* use an arch-specific implementation */
25 #endif
26
27 /*
28  * lock for reading
29  */
30 static inline void down_read(struct rw_semaphore *sem)
31 {
32         might_sleep();
33         __down_read(sem);
34 }
35
36 /*
37  * trylock for reading -- returns 1 if successful, 0 if contention
38  */
39 static inline int down_read_trylock(struct rw_semaphore *sem)
40 {
41         int ret;
42         ret = __down_read_trylock(sem);
43         return ret;
44 }
45
46 /*
47  * lock for writing
48  */
49 static inline void down_write(struct rw_semaphore *sem)
50 {
51         might_sleep();
52         __down_write(sem);
53 }
54
55 /*
56  * trylock for writing -- returns 1 if successful, 0 if contention
57  */
58 static inline int down_write_trylock(struct rw_semaphore *sem)
59 {
60         int ret;
61         ret = __down_write_trylock(sem);
62         return ret;
63 }
64
65 /*
66  * release a read lock
67  */
68 static inline void up_read(struct rw_semaphore *sem)
69 {
70         __up_read(sem);
71 }
72
73 /*
74  * release a write lock
75  */
76 static inline void up_write(struct rw_semaphore *sem)
77 {
78         __up_write(sem);
79 }
80
81 /*
82  * downgrade write lock to read lock
83  */
84 static inline void downgrade_write(struct rw_semaphore *sem)
85 {
86         __downgrade_write(sem);
87 }
88
89 #endif /* __KERNEL__ */
90 #endif /* _LINUX_RWSEM_H */