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 * Trylock by Brian Watson (Brian.J.Watson@compaq.com).
7 */
8
9 #ifndef _LINUX_RWSEM_H
10 #define _LINUX_RWSEM_H
11
12 #include <linux/linkage.h>
13
14 #define RWSEM_DEBUG 0
15
16 #ifdef __KERNEL__
17
18 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <asm/system.h>
22 #include <asm/atomic.h>
23
24 struct rw_semaphore;
25
26 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
27 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
28 #else
29 #include <asm/rwsem.h> /* use an arch-specific implementation */
30 #endif
31
32 #ifndef rwsemtrace
33 #if RWSEM_DEBUG
34 extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
35 #else
36 #define rwsemtrace(SEM,FMT)
37 #endif
38 #endif
39
40 /*
41 * lock for reading
42 */
down_read(struct rw_semaphore * sem)43 static inline void down_read(struct rw_semaphore *sem)
44 {
45 rwsemtrace(sem,"Entering down_read");
46 __down_read(sem);
47 rwsemtrace(sem,"Leaving down_read");
48 }
49
50 /*
51 * trylock for reading -- returns 1 if successful, 0 if contention
52 */
down_read_trylock(struct rw_semaphore * sem)53 static inline int down_read_trylock(struct rw_semaphore *sem)
54 {
55 int ret;
56 rwsemtrace(sem,"Entering down_read_trylock");
57 ret = __down_read_trylock(sem);
58 rwsemtrace(sem,"Leaving down_read_trylock");
59 return ret;
60 }
61
62 /*
63 * lock for writing
64 */
down_write(struct rw_semaphore * sem)65 static inline void down_write(struct rw_semaphore *sem)
66 {
67 rwsemtrace(sem,"Entering down_write");
68 __down_write(sem);
69 rwsemtrace(sem,"Leaving down_write");
70 }
71
72 /*
73 * trylock for writing -- returns 1 if successful, 0 if contention
74 */
down_write_trylock(struct rw_semaphore * sem)75 static inline int down_write_trylock(struct rw_semaphore *sem)
76 {
77 int ret;
78 rwsemtrace(sem,"Entering down_write_trylock");
79 ret = __down_write_trylock(sem);
80 rwsemtrace(sem,"Leaving down_write_trylock");
81 return ret;
82 }
83
84 /*
85 * release a read lock
86 */
up_read(struct rw_semaphore * sem)87 static inline void up_read(struct rw_semaphore *sem)
88 {
89 rwsemtrace(sem,"Entering up_read");
90 __up_read(sem);
91 rwsemtrace(sem,"Leaving up_read");
92 }
93
94 /*
95 * release a write lock
96 */
up_write(struct rw_semaphore * sem)97 static inline void up_write(struct rw_semaphore *sem)
98 {
99 rwsemtrace(sem,"Entering up_write");
100 __up_write(sem);
101 rwsemtrace(sem,"Leaving up_write");
102 }
103
104
105 #endif /* __KERNEL__ */
106 #endif /* _LINUX_RWSEM_H */
107