rwsem.h 1.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/* rwsem.h: R/W semaphores, public interface
 *
 * Written by David Howells (dhowells@redhat.com).
 * Derived from asm-i386/semaphore.h
 */

#ifndef _LINUX_RWSEM_H
#define _LINUX_RWSEM_H

#include <linux/linkage.h>

#ifdef __KERNEL__

#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/system.h>
#include <asm/atomic.h>

struct rw_semaphore;

#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
#include <linux/rwsem-spinlock.h> /* use a generic implementation */
#else
#include <asm/rwsem.h> /* use an arch-specific implementation */
#endif

/*
 * lock for reading
 */
30
extern void down_read(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
31 32 33 34

/*
 * trylock for reading -- returns 1 if successful, 0 if contention
 */
35
extern int down_read_trylock(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
36 37 38 39

/*
 * lock for writing
 */
40
extern void down_write(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
41 42 43 44

/*
 * trylock for writing -- returns 1 if successful, 0 if contention
 */
45
extern int down_write_trylock(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
46 47 48 49

/*
 * release a read lock
 */
50
extern void up_read(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
51 52 53 54

/*
 * release a write lock
 */
55
extern void up_write(struct rw_semaphore *sem);
L
Linus Torvalds 已提交
56 57 58 59

/*
 * downgrade write lock to read lock
 */
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
extern void downgrade_write(struct rw_semaphore *sem);

#ifdef CONFIG_DEBUG_LOCK_ALLOC
/*
 * nested locking:
 */
extern void down_read_nested(struct rw_semaphore *sem, int subclass);
extern void down_write_nested(struct rw_semaphore *sem, int subclass);
/*
 * Take/release a lock when not the owner will release it:
 */
extern void down_read_non_owner(struct rw_semaphore *sem);
extern void up_read_non_owner(struct rw_semaphore *sem);
#else
# define down_read_nested(sem, subclass)		down_read(sem)
# define down_write_nested(sem, subclass)	down_write(sem)
# define down_read_non_owner(sem)		down_read(sem)
# define up_read_non_owner(sem)			up_read(sem)
#endif
L
Linus Torvalds 已提交
79 80 81

#endif /* __KERNEL__ */
#endif /* _LINUX_RWSEM_H */