blob: 658afb37c3f51456766ffb10e02a336462189ec2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* rwsem.h: R/W semaphores, public interface
2 *
3 * Written by David Howells (dhowells@redhat.com).
4 * Derived from asm-i386/semaphore.h
5 */
6
7#ifndef _LINUX_RWSEM_H
8#define _LINUX_RWSEM_H
9
10#include <linux/linkage.h>
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifdef __KERNEL__
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
15#include <linux/kernel.h>
16#include <asm/system.h>
17#include <asm/atomic.h>
18
19struct rw_semaphore;
20
21#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
22#include <linux/rwsem-spinlock.h> /* use a generic implementation */
23#else
24#include <asm/rwsem.h> /* use an arch-specific implementation */
25#endif
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/*
28 * lock for reading
29 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070030extern void down_read(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
33 * trylock for reading -- returns 1 if successful, 0 if contention
34 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070035extern int down_read_trylock(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
38 * lock for writing
39 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070040extern void down_write(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42/*
43 * trylock for writing -- returns 1 if successful, 0 if contention
44 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070045extern int down_write_trylock(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/*
48 * release a read lock
49 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070050extern void up_read(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*
53 * release a write lock
54 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070055extern void up_write(struct rw_semaphore *sem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/*
58 * downgrade write lock to read lock
59 */
Ingo Molnar4ea21762006-07-03 00:24:53 -070060extern void downgrade_write(struct rw_semaphore *sem);
61
62#ifdef CONFIG_DEBUG_LOCK_ALLOC
63/*
64 * nested locking:
65 */
66extern void down_read_nested(struct rw_semaphore *sem, int subclass);
67extern void down_write_nested(struct rw_semaphore *sem, int subclass);
68/*
69 * Take/release a lock when not the owner will release it:
70 */
71extern void down_read_non_owner(struct rw_semaphore *sem);
72extern void up_read_non_owner(struct rw_semaphore *sem);
73#else
74# define down_read_nested(sem, subclass) down_read(sem)
75# define down_write_nested(sem, subclass) down_write(sem)
76# define down_read_non_owner(sem) down_read(sem)
77# define up_read_non_owner(sem) up_read(sem)
78#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80#endif /* __KERNEL__ */
81#endif /* _LINUX_RWSEM_H */