Merge branch 'master' into upstream
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / rwsem.h
blobf99fe90732abfe7cc0bdbc0e103fd0b717950bd4
1 /* rwsem.h: R/W semaphores, public interface
3 * Written by David Howells (dhowells@redhat.com).
4 * Derived from asm-i386/semaphore.h
5 */
7 #ifndef _LINUX_RWSEM_H
8 #define _LINUX_RWSEM_H
10 #include <linux/linkage.h>
12 #define RWSEM_DEBUG 0
14 #ifdef __KERNEL__
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <asm/system.h>
19 #include <asm/atomic.h>
21 struct rw_semaphore;
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
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
38 * lock for reading
40 static inline void down_read(struct rw_semaphore *sem)
42 might_sleep();
43 rwsemtrace(sem,"Entering down_read");
44 __down_read(sem);
45 rwsemtrace(sem,"Leaving down_read");
49 * trylock for reading -- returns 1 if successful, 0 if contention
51 static inline int down_read_trylock(struct rw_semaphore *sem)
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;
61 * lock for writing
63 static inline void down_write(struct rw_semaphore *sem)
65 might_sleep();
66 rwsemtrace(sem,"Entering down_write");
67 __down_write(sem);
68 rwsemtrace(sem,"Leaving down_write");
72 * trylock for writing -- returns 1 if successful, 0 if contention
74 static inline int down_write_trylock(struct rw_semaphore *sem)
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;
84 * release a read lock
86 static inline void up_read(struct rw_semaphore *sem)
88 rwsemtrace(sem,"Entering up_read");
89 __up_read(sem);
90 rwsemtrace(sem,"Leaving up_read");
94 * release a write lock
96 static inline void up_write(struct rw_semaphore *sem)
98 rwsemtrace(sem,"Entering up_write");
99 __up_write(sem);
100 rwsemtrace(sem,"Leaving up_write");
104 * downgrade write lock to read lock
106 static inline void downgrade_write(struct rw_semaphore *sem)
108 rwsemtrace(sem,"Entering downgrade_write");
109 __downgrade_write(sem);
110 rwsemtrace(sem,"Leaving downgrade_write");
113 #endif /* __KERNEL__ */
114 #endif /* _LINUX_RWSEM_H */