rwsem: Move duplicate struct rwsem declaration to linux/rwsem.h
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / rwsem.h
CommitLineData
1da177e4
LT
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
1da177e4
LT
12#include <linux/types.h>
13#include <linux/kernel.h>
c16a87ce
TG
14#include <linux/list.h>
15#include <linux/spinlock.h>
16
1da177e4
LT
17#include <asm/system.h>
18#include <asm/atomic.h>
19
20struct rw_semaphore;
21
22#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
23#include <linux/rwsem-spinlock.h> /* use a generic implementation */
24#else
1c8ed640
TG
25/* All arch specific implementations share the same struct */
26struct rw_semaphore {
27 long count;
28 spinlock_t wait_lock;
29 struct list_head wait_list;
30#ifdef CONFIG_DEBUG_LOCK_ALLOC
31 struct lockdep_map dep_map;
32#endif
33};
34
35/* Include the arch specific part */
36#include <asm/rwsem.h>
1da177e4
LT
37#endif
38
1da177e4
LT
39/*
40 * lock for reading
41 */
4ea2176d 42extern void down_read(struct rw_semaphore *sem);
1da177e4
LT
43
44/*
45 * trylock for reading -- returns 1 if successful, 0 if contention
46 */
4ea2176d 47extern int down_read_trylock(struct rw_semaphore *sem);
1da177e4
LT
48
49/*
50 * lock for writing
51 */
4ea2176d 52extern void down_write(struct rw_semaphore *sem);
1da177e4
LT
53
54/*
55 * trylock for writing -- returns 1 if successful, 0 if contention
56 */
4ea2176d 57extern int down_write_trylock(struct rw_semaphore *sem);
1da177e4
LT
58
59/*
60 * release a read lock
61 */
4ea2176d 62extern void up_read(struct rw_semaphore *sem);
1da177e4
LT
63
64/*
65 * release a write lock
66 */
4ea2176d 67extern void up_write(struct rw_semaphore *sem);
1da177e4
LT
68
69/*
70 * downgrade write lock to read lock
71 */
4ea2176d
IM
72extern void downgrade_write(struct rw_semaphore *sem);
73
74#ifdef CONFIG_DEBUG_LOCK_ALLOC
75/*
5fca80e8
IM
76 * nested locking. NOTE: rwsems are not allowed to recurse
77 * (which occurs if the same task tries to acquire the same
78 * lock instance multiple times), but multiple locks of the
79 * same lock class might be taken, if the order of the locks
80 * is always the same. This ordering rule can be expressed
81 * to lockdep via the _nested() APIs, but enumerating the
82 * subclasses that are used. (If the nesting relationship is
83 * static then another method for expressing nested locking is
84 * the explicit definition of lock class keys and the use of
85 * lockdep_set_class() at lock initialization time.
86 * See Documentation/lockdep-design.txt for more details.)
4ea2176d
IM
87 */
88extern void down_read_nested(struct rw_semaphore *sem, int subclass);
89extern void down_write_nested(struct rw_semaphore *sem, int subclass);
90/*
5fca80e8
IM
91 * Take/release a lock when not the owner will release it.
92 *
93 * [ This API should be avoided as much as possible - the
94 * proper abstraction for this case is completions. ]
4ea2176d
IM
95 */
96extern void down_read_non_owner(struct rw_semaphore *sem);
97extern void up_read_non_owner(struct rw_semaphore *sem);
98#else
99# define down_read_nested(sem, subclass) down_read(sem)
100# define down_write_nested(sem, subclass) down_write(sem)
101# define down_read_non_owner(sem) down_read(sem)
102# define up_read_non_owner(sem) up_read(sem)
103#endif
1da177e4 104
1da177e4 105#endif /* _LINUX_RWSEM_H */