diff options
Diffstat (limited to 'include/linux/rwsem.h')
| -rw-r--r-- | include/linux/rwsem.h | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index efd348fe8ca7..a8afe9cd000c 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h | |||
| @@ -11,6 +11,9 @@ | |||
| 11 | 11 | ||
| 12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/list.h> | ||
| 15 | #include <linux/spinlock.h> | ||
| 16 | |||
| 14 | #include <asm/system.h> | 17 | #include <asm/system.h> |
| 15 | #include <asm/atomic.h> | 18 | #include <asm/atomic.h> |
| 16 | 19 | ||
| @@ -19,9 +22,57 @@ struct rw_semaphore; | |||
| 19 | #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK | 22 | #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK |
| 20 | #include <linux/rwsem-spinlock.h> /* use a generic implementation */ | 23 | #include <linux/rwsem-spinlock.h> /* use a generic implementation */ |
| 21 | #else | 24 | #else |
| 22 | #include <asm/rwsem.h> /* use an arch-specific implementation */ | 25 | /* All arch specific implementations share the same struct */ |
| 26 | struct rw_semaphore { | ||
| 27 | long count; | ||
| 28 | spinlock_t wait_lock; | ||
| 29 | struct list_head wait_list; | ||
| 30 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 31 | struct lockdep_map dep_map; | ||
| 32 | #endif | ||
| 33 | }; | ||
| 34 | |||
| 35 | extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem); | ||
| 36 | extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem); | ||
| 37 | extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *); | ||
| 38 | extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem); | ||
| 39 | |||
| 40 | /* Include the arch specific part */ | ||
| 41 | #include <asm/rwsem.h> | ||
| 42 | |||
| 43 | /* In all implementations count != 0 means locked */ | ||
| 44 | static inline int rwsem_is_locked(struct rw_semaphore *sem) | ||
| 45 | { | ||
| 46 | return sem->count != 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | #endif | ||
| 50 | |||
| 51 | /* Common initializer macros and functions */ | ||
| 52 | |||
| 53 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 54 | # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname } | ||
| 55 | #else | ||
| 56 | # define __RWSEM_DEP_MAP_INIT(lockname) | ||
| 23 | #endif | 57 | #endif |
| 24 | 58 | ||
| 59 | #define __RWSEM_INITIALIZER(name) \ | ||
| 60 | { RWSEM_UNLOCKED_VALUE, __SPIN_LOCK_UNLOCKED(name.wait_lock), \ | ||
| 61 | LIST_HEAD_INIT((name).wait_list) __RWSEM_DEP_MAP_INIT(name) } | ||
| 62 | |||
| 63 | #define DECLARE_RWSEM(name) \ | ||
| 64 | struct rw_semaphore name = __RWSEM_INITIALIZER(name) | ||
| 65 | |||
| 66 | extern void __init_rwsem(struct rw_semaphore *sem, const char *name, | ||
| 67 | struct lock_class_key *key); | ||
| 68 | |||
| 69 | #define init_rwsem(sem) \ | ||
| 70 | do { \ | ||
| 71 | static struct lock_class_key __key; \ | ||
| 72 | \ | ||
| 73 | __init_rwsem((sem), #sem, &__key); \ | ||
| 74 | } while (0) | ||
| 75 | |||
| 25 | /* | 76 | /* |
| 26 | * lock for reading | 77 | * lock for reading |
| 27 | */ | 78 | */ |
