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>
12 #include <linux/types.h>
13 #include <linux/kernel.h>
14 #include <asm/system.h>
15 #include <asm/atomic.h>
19 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
20 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
22 #include <asm/rwsem.h> /* use an arch-specific implementation */
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
);
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
);
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
);
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)
91 #endif /* _LINUX_RWSEM_H */