hpsa: add in P840ar controller model name
[linux/fpc-iii.git] / kernel / locking / rwsem.c
blobe2d3bc7f03b41e1c01a7c8fc548ac162cdfa151e
1 /* kernel/rwsem.c: R/W semaphores, public implementation
3 * Written by David Howells (dhowells@redhat.com).
4 * Derived from asm-i386/semaphore.h
5 */
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/export.h>
11 #include <linux/rwsem.h>
13 #include <linux/atomic.h>
15 #ifdef CONFIG_RWSEM_SPIN_ON_OWNER
16 static inline void rwsem_set_owner(struct rw_semaphore *sem)
18 sem->owner = current;
21 static inline void rwsem_clear_owner(struct rw_semaphore *sem)
23 sem->owner = NULL;
26 #else
27 static inline void rwsem_set_owner(struct rw_semaphore *sem)
31 static inline void rwsem_clear_owner(struct rw_semaphore *sem)
34 #endif
37 * lock for reading
39 void __sched down_read(struct rw_semaphore *sem)
41 might_sleep();
42 rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
44 LOCK_CONTENDED(sem, __down_read_trylock, __down_read);
47 EXPORT_SYMBOL(down_read);
50 * trylock for reading -- returns 1 if successful, 0 if contention
52 int down_read_trylock(struct rw_semaphore *sem)
54 int ret = __down_read_trylock(sem);
56 if (ret == 1)
57 rwsem_acquire_read(&sem->dep_map, 0, 1, _RET_IP_);
58 return ret;
61 EXPORT_SYMBOL(down_read_trylock);
64 * lock for writing
66 void __sched down_write(struct rw_semaphore *sem)
68 might_sleep();
69 rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
71 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
72 rwsem_set_owner(sem);
75 EXPORT_SYMBOL(down_write);
78 * trylock for writing -- returns 1 if successful, 0 if contention
80 int down_write_trylock(struct rw_semaphore *sem)
82 int ret = __down_write_trylock(sem);
84 if (ret == 1) {
85 rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_);
86 rwsem_set_owner(sem);
89 return ret;
92 EXPORT_SYMBOL(down_write_trylock);
95 * release a read lock
97 void up_read(struct rw_semaphore *sem)
99 rwsem_release(&sem->dep_map, 1, _RET_IP_);
101 __up_read(sem);
104 EXPORT_SYMBOL(up_read);
107 * release a write lock
109 void up_write(struct rw_semaphore *sem)
111 rwsem_release(&sem->dep_map, 1, _RET_IP_);
113 rwsem_clear_owner(sem);
114 __up_write(sem);
117 EXPORT_SYMBOL(up_write);
120 * downgrade write lock to read lock
122 void downgrade_write(struct rw_semaphore *sem)
125 * lockdep: a downgraded write will live on as a write
126 * dependency.
128 rwsem_clear_owner(sem);
129 __downgrade_write(sem);
132 EXPORT_SYMBOL(downgrade_write);
134 #ifdef CONFIG_DEBUG_LOCK_ALLOC
136 void down_read_nested(struct rw_semaphore *sem, int subclass)
138 might_sleep();
139 rwsem_acquire_read(&sem->dep_map, subclass, 0, _RET_IP_);
141 LOCK_CONTENDED(sem, __down_read_trylock, __down_read);
144 EXPORT_SYMBOL(down_read_nested);
146 void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest)
148 might_sleep();
149 rwsem_acquire_nest(&sem->dep_map, 0, 0, nest, _RET_IP_);
151 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
152 rwsem_set_owner(sem);
155 EXPORT_SYMBOL(_down_write_nest_lock);
157 void down_read_non_owner(struct rw_semaphore *sem)
159 might_sleep();
161 __down_read(sem);
164 EXPORT_SYMBOL(down_read_non_owner);
166 void down_write_nested(struct rw_semaphore *sem, int subclass)
168 might_sleep();
169 rwsem_acquire(&sem->dep_map, subclass, 0, _RET_IP_);
171 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
172 rwsem_set_owner(sem);
175 EXPORT_SYMBOL(down_write_nested);
177 void up_read_non_owner(struct rw_semaphore *sem)
179 __up_read(sem);
182 EXPORT_SYMBOL(up_read_non_owner);
184 #endif