nl80211: Fix HT_IBSS feature check in ibss_join
[linux-2.6.git] / include / linux / rwsem.h
blob54bd7cd7ecbd11449b9e15b49f9ab7e208e96413
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 <linux/list.h>
15 #include <linux/spinlock.h>
17 #include <linux/atomic.h>
19 struct rw_semaphore;
21 #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
22 #include <linux/rwsem-spinlock.h> /* use a generic implementation */
23 #else
24 /* All arch specific implementations share the same struct */
25 struct rw_semaphore {
26 long count;
27 raw_spinlock_t wait_lock;
28 struct list_head wait_list;
29 #ifdef CONFIG_DEBUG_LOCK_ALLOC
30 struct lockdep_map dep_map;
31 #endif
34 extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem);
35 extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem);
36 extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *);
37 extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem);
39 /* Include the arch specific part */
40 #include <asm/rwsem.h>
42 /* In all implementations count != 0 means locked */
43 static inline int rwsem_is_locked(struct rw_semaphore *sem)
45 return sem->count != 0;
48 #endif
50 /* Common initializer macros and functions */
52 #ifdef CONFIG_DEBUG_LOCK_ALLOC
53 # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
54 #else
55 # define __RWSEM_DEP_MAP_INIT(lockname)
56 #endif
58 #define __RWSEM_INITIALIZER(name) \
59 { RWSEM_UNLOCKED_VALUE, \
60 __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
61 LIST_HEAD_INIT((name).wait_list) \
62 __RWSEM_DEP_MAP_INIT(name) }
64 #define DECLARE_RWSEM(name) \
65 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
67 extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
68 struct lock_class_key *key);
70 #define init_rwsem(sem) \
71 do { \
72 static struct lock_class_key __key; \
74 __init_rwsem((sem), #sem, &__key); \
75 } while (0)
78 * lock for reading
80 extern void down_read(struct rw_semaphore *sem);
83 * trylock for reading -- returns 1 if successful, 0 if contention
85 extern int down_read_trylock(struct rw_semaphore *sem);
88 * lock for writing
90 extern void down_write(struct rw_semaphore *sem);
93 * trylock for writing -- returns 1 if successful, 0 if contention
95 extern int down_write_trylock(struct rw_semaphore *sem);
98 * release a read lock
100 extern void up_read(struct rw_semaphore *sem);
103 * release a write lock
105 extern void up_write(struct rw_semaphore *sem);
108 * downgrade write lock to read lock
110 extern void downgrade_write(struct rw_semaphore *sem);
112 #ifdef CONFIG_DEBUG_LOCK_ALLOC
114 * nested locking. NOTE: rwsems are not allowed to recurse
115 * (which occurs if the same task tries to acquire the same
116 * lock instance multiple times), but multiple locks of the
117 * same lock class might be taken, if the order of the locks
118 * is always the same. This ordering rule can be expressed
119 * to lockdep via the _nested() APIs, but enumerating the
120 * subclasses that are used. (If the nesting relationship is
121 * static then another method for expressing nested locking is
122 * the explicit definition of lock class keys and the use of
123 * lockdep_set_class() at lock initialization time.
124 * See Documentation/lockdep-design.txt for more details.)
126 extern void down_read_nested(struct rw_semaphore *sem, int subclass);
127 extern void down_write_nested(struct rw_semaphore *sem, int subclass);
128 #else
129 # define down_read_nested(sem, subclass) down_read(sem)
130 # define down_write_nested(sem, subclass) down_write(sem)
131 #endif
133 #endif /* _LINUX_RWSEM_H */