]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - kernel/rwsem.c
1 /* kernel/rwsem.c: R/W semaphores, public implementation
3 * Written by David Howells (dhowells@redhat.com).
4 * Derived from asm-i386/semaphore.h
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>
18 void __sched
down_read(struct rw_semaphore
*sem
)
21 rwsem_acquire_read(&sem
->dep_map
, 0, 0, _RET_IP_
);
23 LOCK_CONTENDED(sem
, __down_read_trylock
, __down_read
);
26 EXPORT_SYMBOL(down_read
);
29 * trylock for reading -- returns 1 if successful, 0 if contention
31 int down_read_trylock(struct rw_semaphore
*sem
)
33 int ret
= __down_read_trylock(sem
);
36 rwsem_acquire_read(&sem
->dep_map
, 0, 1, _RET_IP_
);
40 EXPORT_SYMBOL(down_read_trylock
);
45 void __sched
down_write(struct rw_semaphore
*sem
)
48 rwsem_acquire(&sem
->dep_map
, 0, 0, _RET_IP_
);
50 LOCK_CONTENDED(sem
, __down_write_trylock
, __down_write
);
53 EXPORT_SYMBOL(down_write
);
56 * trylock for writing -- returns 1 if successful, 0 if contention
58 int down_write_trylock(struct rw_semaphore
*sem
)
60 int ret
= __down_write_trylock(sem
);
63 rwsem_acquire(&sem
->dep_map
, 0, 1, _RET_IP_
);
67 EXPORT_SYMBOL(down_write_trylock
);
72 void up_read(struct rw_semaphore
*sem
)
74 rwsem_release(&sem
->dep_map
, 1, _RET_IP_
);
79 EXPORT_SYMBOL(up_read
);
82 * release a write lock
84 void up_write(struct rw_semaphore
*sem
)
86 rwsem_release(&sem
->dep_map
, 1, _RET_IP_
);
91 EXPORT_SYMBOL(up_write
);
94 * downgrade write lock to read lock
96 void downgrade_write(struct rw_semaphore
*sem
)
99 * lockdep: a downgraded write will live on as a write
102 __downgrade_write(sem
);
105 EXPORT_SYMBOL(downgrade_write
);
107 #ifdef CONFIG_DEBUG_LOCK_ALLOC
109 void down_read_nested(struct rw_semaphore
*sem
, int subclass
)
112 rwsem_acquire_read(&sem
->dep_map
, subclass
, 0, _RET_IP_
);
114 LOCK_CONTENDED(sem
, __down_read_trylock
, __down_read
);
117 EXPORT_SYMBOL(down_read_nested
);
119 void _down_write_nest_lock(struct rw_semaphore
*sem
, struct lockdep_map
*nest
)
122 rwsem_acquire_nest(&sem
->dep_map
, 0, 0, nest
, _RET_IP_
);
124 LOCK_CONTENDED(sem
, __down_write_trylock
, __down_write
);
127 EXPORT_SYMBOL(_down_write_nest_lock
);
129 void down_read_non_owner(struct rw_semaphore
*sem
)
136 EXPORT_SYMBOL(down_read_non_owner
);
138 void down_write_nested(struct rw_semaphore
*sem
, int subclass
)
141 rwsem_acquire(&sem
->dep_map
, subclass
, 0, _RET_IP_
);
143 LOCK_CONTENDED(sem
, __down_write_trylock
, __down_write
);
146 EXPORT_SYMBOL(down_write_nested
);
148 void up_read_non_owner(struct rw_semaphore
*sem
)
153 EXPORT_SYMBOL(up_read_non_owner
);