natsemi: add checks for dma mapping errors
[linux/fpc-iii.git] / kernel / locking / rwsem.c
blob205be0ce34de73e8590f2cd4cdb369526b236540
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>
12 #include <linux/atomic.h>
14 #include "rwsem.h"
17 * lock for reading
19 void __sched down_read(struct rw_semaphore *sem)
21 might_sleep();
22 rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_);
24 LOCK_CONTENDED(sem, __down_read_trylock, __down_read);
27 EXPORT_SYMBOL(down_read);
30 * trylock for reading -- returns 1 if successful, 0 if contention
32 int down_read_trylock(struct rw_semaphore *sem)
34 int ret = __down_read_trylock(sem);
36 if (ret == 1)
37 rwsem_acquire_read(&sem->dep_map, 0, 1, _RET_IP_);
38 return ret;
41 EXPORT_SYMBOL(down_read_trylock);
44 * lock for writing
46 void __sched down_write(struct rw_semaphore *sem)
48 might_sleep();
49 rwsem_acquire(&sem->dep_map, 0, 0, _RET_IP_);
51 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
52 rwsem_set_owner(sem);
55 EXPORT_SYMBOL(down_write);
58 * trylock for writing -- returns 1 if successful, 0 if contention
60 int down_write_trylock(struct rw_semaphore *sem)
62 int ret = __down_write_trylock(sem);
64 if (ret == 1) {
65 rwsem_acquire(&sem->dep_map, 0, 1, _RET_IP_);
66 rwsem_set_owner(sem);
69 return ret;
72 EXPORT_SYMBOL(down_write_trylock);
75 * release a read lock
77 void up_read(struct rw_semaphore *sem)
79 rwsem_release(&sem->dep_map, 1, _RET_IP_);
81 __up_read(sem);
84 EXPORT_SYMBOL(up_read);
87 * release a write lock
89 void up_write(struct rw_semaphore *sem)
91 rwsem_release(&sem->dep_map, 1, _RET_IP_);
93 rwsem_clear_owner(sem);
94 __up_write(sem);
97 EXPORT_SYMBOL(up_write);
100 * downgrade write lock to read lock
102 void downgrade_write(struct rw_semaphore *sem)
105 * lockdep: a downgraded write will live on as a write
106 * dependency.
108 rwsem_clear_owner(sem);
109 __downgrade_write(sem);
112 EXPORT_SYMBOL(downgrade_write);
114 #ifdef CONFIG_DEBUG_LOCK_ALLOC
116 void down_read_nested(struct rw_semaphore *sem, int subclass)
118 might_sleep();
119 rwsem_acquire_read(&sem->dep_map, subclass, 0, _RET_IP_);
121 LOCK_CONTENDED(sem, __down_read_trylock, __down_read);
124 EXPORT_SYMBOL(down_read_nested);
126 void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest)
128 might_sleep();
129 rwsem_acquire_nest(&sem->dep_map, 0, 0, nest, _RET_IP_);
131 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
132 rwsem_set_owner(sem);
135 EXPORT_SYMBOL(_down_write_nest_lock);
137 void down_read_non_owner(struct rw_semaphore *sem)
139 might_sleep();
141 __down_read(sem);
144 EXPORT_SYMBOL(down_read_non_owner);
146 void down_write_nested(struct rw_semaphore *sem, int subclass)
148 might_sleep();
149 rwsem_acquire(&sem->dep_map, subclass, 0, _RET_IP_);
151 LOCK_CONTENDED(sem, __down_write_trylock, __down_write);
152 rwsem_set_owner(sem);
155 EXPORT_SYMBOL(down_write_nested);
157 void up_read_non_owner(struct rw_semaphore *sem)
159 __up_read(sem);
162 EXPORT_SYMBOL(up_read_non_owner);
164 #endif