aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rwsem.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/rwsem.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/linux/rwsem.h')
-rw-r--r--include/linux/rwsem.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
new file mode 100644
index 000000000000..bfb988885002
--- /dev/null
+++ b/include/linux/rwsem.h
@@ -0,0 +1,115 @@
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/config.h>
17#include <linux/types.h>
18#include <linux/kernel.h>
19#include <asm/system.h>
20#include <asm/atomic.h>
21
22struct rw_semaphore;
23
24#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
25#include <linux/rwsem-spinlock.h> /* use a generic implementation */
26#else
27#include <asm/rwsem.h> /* use an arch-specific implementation */
28#endif
29
30#ifndef rwsemtrace
31#if RWSEM_DEBUG
32extern void FASTCALL(rwsemtrace(struct rw_semaphore *sem, const char *str));
33#else
34#define rwsemtrace(SEM,FMT)
35#endif
36#endif
37
38/*
39 * lock for reading
40 */
41static inline void down_read(struct rw_semaphore *sem)
42{
43 might_sleep();
44 rwsemtrace(sem,"Entering down_read");
45 __down_read(sem);
46 rwsemtrace(sem,"Leaving down_read");
47}
48
49/*
50 * trylock for reading -- returns 1 if successful, 0 if contention
51 */
52static inline int down_read_trylock(struct rw_semaphore *sem)
53{
54 int ret;
55 rwsemtrace(sem,"Entering down_read_trylock");
56 ret = __down_read_trylock(sem);
57 rwsemtrace(sem,"Leaving down_read_trylock");
58 return ret;
59}
60
61/*
62 * lock for writing
63 */
64static inline void down_write(struct rw_semaphore *sem)
65{
66 might_sleep();
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 */
75static 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 */
87static 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 */
97static 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 * downgrade write lock to read lock
106 */
107static inline void downgrade_write(struct rw_semaphore *sem)
108{
109 rwsemtrace(sem,"Entering downgrade_write");
110 __downgrade_write(sem);
111 rwsemtrace(sem,"Leaving downgrade_write");
112}
113
114#endif /* __KERNEL__ */
115#endif /* _LINUX_RWSEM_H */