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/module.h>
11 #include <linux/rwsem.h>
13 #include <asm/system.h>
14 #include <asm/atomic.h>
19 void __sched
compat_down_read(struct compat_rw_semaphore
*sem
)
22 rwsem_acquire_read(&sem
->dep_map
, 0, 0, _RET_IP_
);
24 LOCK_CONTENDED(sem
, __down_read_trylock
, __down_read
);
27 EXPORT_SYMBOL(compat_down_read
);
30 * trylock for reading -- returns 1 if successful, 0 if contention
32 int compat_down_read_trylock(struct compat_rw_semaphore
*sem
)
34 int ret
= __down_read_trylock(sem
);
37 rwsem_acquire_read(&sem
->dep_map
, 0, 1, _RET_IP_
);
41 EXPORT_SYMBOL(compat_down_read_trylock
);
46 void __sched
compat_down_write(struct compat_rw_semaphore
*sem
)
49 rwsem_acquire(&sem
->dep_map
, 0, 0, _RET_IP_
);
51 LOCK_CONTENDED(sem
, __down_write_trylock
, __down_write
);
54 EXPORT_SYMBOL(compat_down_write
);
57 * trylock for writing -- returns 1 if successful, 0 if contention
59 int compat_down_write_trylock(struct compat_rw_semaphore
*sem
)
61 int ret
= __down_write_trylock(sem
);
64 rwsem_acquire(&sem
->dep_map
, 0, 1, _RET_IP_
);
68 EXPORT_SYMBOL(compat_down_write_trylock
);
73 void compat_up_read(struct compat_rw_semaphore
*sem
)
75 rwsem_release(&sem
->dep_map
, 1, _RET_IP_
);
80 EXPORT_SYMBOL(compat_up_read
);
83 * release a write lock
85 void compat_up_write(struct compat_rw_semaphore
*sem
)
87 rwsem_release(&sem
->dep_map
, 1, _RET_IP_
);
92 EXPORT_SYMBOL(compat_up_write
);
95 * downgrade write lock to read lock
97 void compat_downgrade_write(struct compat_rw_semaphore
*sem
)
100 * lockdep: a downgraded write will live on as a write
103 __downgrade_write(sem
);
106 EXPORT_SYMBOL(compat_downgrade_write
);
108 #ifdef CONFIG_DEBUG_LOCK_ALLOC
110 void compat_down_read_nested(struct compat_rw_semaphore
*sem
, int subclass
)
113 rwsem_acquire_read(&sem
->dep_map
, subclass
, 0, _RET_IP_
);
115 LOCK_CONTENDED(sem
, __down_read_trylock
, __down_read
);
118 EXPORT_SYMBOL(compat_down_read_nested
);
120 void compat_down_read_non_owner(struct compat_rw_semaphore
*sem
)
127 EXPORT_SYMBOL(compat_down_read_non_owner
);
129 void compat_down_write_nested(struct compat_rw_semaphore
*sem
, int subclass
)
132 rwsem_acquire(&sem
->dep_map
, subclass
, 0, _RET_IP_
);
134 LOCK_CONTENDED(sem
, __down_write_trylock
, __down_write
);
137 EXPORT_SYMBOL(compat_down_write_nested
);
139 void compat_up_read_non_owner(struct compat_rw_semaphore
*sem
)
144 EXPORT_SYMBOL(compat_up_read_non_owner
);