1 /* rwsem.h: R/W semaphores, public interface
3 * Written by David Howells (dhowells@redhat.com).
4 * Derived from asm-i386/semaphore.h
10 #include <linux/linkage.h>
16 #include <linux/config.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <asm/system.h>
20 #include <asm/atomic.h>
24 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
25 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
27 #include <asm/rwsem.h> /* use an arch-specific implementation */
32 extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
34 #define rwsemtrace(SEM,FMT)
41 static inline void down_read(struct rw_semaphore *sem)
44 rwsemtrace(sem,"Entering down_read");
46 rwsemtrace(sem,"Leaving down_read");
50 * trylock for reading -- returns 1 if successful, 0 if contention
52 static inline int down_read_trylock(struct rw_semaphore *sem)
55 rwsemtrace(sem,"Entering down_read_trylock");
56 ret = __down_read_trylock(sem);
57 rwsemtrace(sem,"Leaving down_read_trylock");
64 static inline void down_write(struct rw_semaphore *sem)
67 rwsemtrace(sem,"Entering down_write");
69 rwsemtrace(sem,"Leaving down_write");
73 * trylock for writing -- returns 1 if successful, 0 if contention
75 static inline int down_write_trylock(struct rw_semaphore *sem)
78 rwsemtrace(sem,"Entering down_write_trylock");
79 ret = __down_write_trylock(sem);
80 rwsemtrace(sem,"Leaving down_write_trylock");
87 static inline void up_read(struct rw_semaphore *sem)
89 rwsemtrace(sem,"Entering up_read");
91 rwsemtrace(sem,"Leaving up_read");
95 * release a write lock
97 static inline void up_write(struct rw_semaphore *sem)
99 rwsemtrace(sem,"Entering up_write");
101 rwsemtrace(sem,"Leaving up_write");
105 * downgrade write lock to read lock
107 static inline void downgrade_write(struct rw_semaphore *sem)
109 rwsemtrace(sem,"Entering downgrade_write");
110 __downgrade_write(sem);
111 rwsemtrace(sem,"Leaving downgrade_write");
114 #endif /* __KERNEL__ */
115 #endif /* _LINUX_RWSEM_H */