HWPOISON: Add simple debugfs interface to inject hwpoison on arbitary PFNs
[linux-2.6.git] / include / linux / rwsem.h
blobefd348fe8ca75f6d9effcf8f05e87bd276e46d97
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 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <asm/system.h>
15 #include <asm/atomic.h>
17 struct rw_semaphore;
19 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
20 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
21 #else
22 #include <asm/rwsem.h> /* use an arch-specific implementation */
23 #endif
26 * lock for reading
28 extern void down_read(struct rw_semaphore *sem);
31 * trylock for reading -- returns 1 if successful, 0 if contention
33 extern int down_read_trylock(struct rw_semaphore *sem);
36 * lock for writing
38 extern void down_write(struct rw_semaphore *sem);
41 * trylock for writing -- returns 1 if successful, 0 if contention
43 extern int down_write_trylock(struct rw_semaphore *sem);
46 * release a read lock
48 extern void up_read(struct rw_semaphore *sem);
51 * release a write lock
53 extern void up_write(struct rw_semaphore *sem);
56 * downgrade write lock to read lock
58 extern void downgrade_write(struct rw_semaphore *sem);
60 #ifdef CONFIG_DEBUG_LOCK_ALLOC
62 * nested locking. NOTE: rwsems are not allowed to recurse
63 * (which occurs if the same task tries to acquire the same
64 * lock instance multiple times), but multiple locks of the
65 * same lock class might be taken, if the order of the locks
66 * is always the same. This ordering rule can be expressed
67 * to lockdep via the _nested() APIs, but enumerating the
68 * subclasses that are used. (If the nesting relationship is
69 * static then another method for expressing nested locking is
70 * the explicit definition of lock class keys and the use of
71 * lockdep_set_class() at lock initialization time.
72 * See Documentation/lockdep-design.txt for more details.)
74 extern void down_read_nested(struct rw_semaphore *sem, int subclass);
75 extern void down_write_nested(struct rw_semaphore *sem, int subclass);
77 * Take/release a lock when not the owner will release it.
79 * [ This API should be avoided as much as possible - the
80 * proper abstraction for this case is completions. ]
82 extern void down_read_non_owner(struct rw_semaphore *sem);
83 extern void up_read_non_owner(struct rw_semaphore *sem);
84 #else
85 # define down_read_nested(sem, subclass) down_read(sem)
86 # define down_write_nested(sem, subclass) down_write(sem)
87 # define down_read_non_owner(sem) down_read(sem)
88 # define up_read_non_owner(sem) up_read(sem)
89 #endif
91 #endif /* _LINUX_RWSEM_H */