Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_SPINLOCK_TYPES_H |
| 2 | #define __LINUX_SPINLOCK_TYPES_H |
| 3 | |
| 4 | /* |
| 5 | * include/linux/spinlock_types.h - generic spinlock type definitions |
| 6 | * and initializers |
| 7 | * |
| 8 | * portions Copyright 2005, Red Hat, Inc., Ingo Molnar |
| 9 | * Released under the General Public License (GPL). |
| 10 | */ |
| 11 | |
| 12 | #if defined(CONFIG_SMP) |
| 13 | # include <asm/spinlock_types.h> |
| 14 | #else |
| 15 | # include <linux/spinlock_types_up.h> |
| 16 | #endif |
| 17 | |
Peter Zijlstra | 21f8ca3 | 2007-07-19 01:48:53 -0700 | [diff] [blame] | 18 | #include <linux/lockdep.h> |
| 19 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 20 | typedef struct { |
| 21 | raw_spinlock_t raw_lock; |
| 22 | #if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP) |
| 23 | unsigned int break_lock; |
| 24 | #endif |
| 25 | #ifdef CONFIG_DEBUG_SPINLOCK |
| 26 | unsigned int magic, owner_cpu; |
| 27 | void *owner; |
| 28 | #endif |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 30 | struct lockdep_map dep_map; |
| 31 | #endif |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 32 | } spinlock_t; |
| 33 | |
| 34 | #define SPINLOCK_MAGIC 0xdead4ead |
| 35 | |
| 36 | typedef struct { |
| 37 | raw_rwlock_t raw_lock; |
| 38 | #if defined(CONFIG_PREEMPT) && defined(CONFIG_SMP) |
| 39 | unsigned int break_lock; |
| 40 | #endif |
| 41 | #ifdef CONFIG_DEBUG_SPINLOCK |
| 42 | unsigned int magic, owner_cpu; |
| 43 | void *owner; |
| 44 | #endif |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 46 | struct lockdep_map dep_map; |
| 47 | #endif |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 48 | } rwlock_t; |
| 49 | |
| 50 | #define RWLOCK_MAGIC 0xdeaf1eed |
| 51 | |
| 52 | #define SPINLOCK_OWNER_INIT ((void *)-1L) |
| 53 | |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 55 | # define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname } |
| 56 | #else |
| 57 | # define SPIN_DEP_MAP_INIT(lockname) |
| 58 | #endif |
| 59 | |
| 60 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 61 | # define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname } |
| 62 | #else |
| 63 | # define RW_DEP_MAP_INIT(lockname) |
| 64 | #endif |
| 65 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 66 | #ifdef CONFIG_DEBUG_SPINLOCK |
Ingo Molnar | e4d9191 | 2006-07-03 00:24:34 -0700 | [diff] [blame] | 67 | # define __SPIN_LOCK_UNLOCKED(lockname) \ |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 68 | (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \ |
| 69 | .magic = SPINLOCK_MAGIC, \ |
| 70 | .owner = SPINLOCK_OWNER_INIT, \ |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 71 | .owner_cpu = -1, \ |
| 72 | SPIN_DEP_MAP_INIT(lockname) } |
Ingo Molnar | e4d9191 | 2006-07-03 00:24:34 -0700 | [diff] [blame] | 73 | #define __RW_LOCK_UNLOCKED(lockname) \ |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 74 | (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \ |
| 75 | .magic = RWLOCK_MAGIC, \ |
| 76 | .owner = SPINLOCK_OWNER_INIT, \ |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 77 | .owner_cpu = -1, \ |
| 78 | RW_DEP_MAP_INIT(lockname) } |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 79 | #else |
Ingo Molnar | e4d9191 | 2006-07-03 00:24:34 -0700 | [diff] [blame] | 80 | # define __SPIN_LOCK_UNLOCKED(lockname) \ |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 81 | (spinlock_t) { .raw_lock = __RAW_SPIN_LOCK_UNLOCKED, \ |
| 82 | SPIN_DEP_MAP_INIT(lockname) } |
Ingo Molnar | e4d9191 | 2006-07-03 00:24:34 -0700 | [diff] [blame] | 83 | #define __RW_LOCK_UNLOCKED(lockname) \ |
Ingo Molnar | 8a25d5d | 2006-07-03 00:24:54 -0700 | [diff] [blame] | 84 | (rwlock_t) { .raw_lock = __RAW_RW_LOCK_UNLOCKED, \ |
| 85 | RW_DEP_MAP_INIT(lockname) } |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 86 | #endif |
| 87 | |
Michael Ellerman | d1ab824 | 2007-05-08 00:30:22 -0700 | [diff] [blame] | 88 | /* |
| 89 | * SPIN_LOCK_UNLOCKED and RW_LOCK_UNLOCKED defeat lockdep state tracking and |
| 90 | * are hence deprecated. |
| 91 | * Please use DEFINE_SPINLOCK()/DEFINE_RWLOCK() or |
| 92 | * __SPIN_LOCK_UNLOCKED()/__RW_LOCK_UNLOCKED() as appropriate. |
| 93 | */ |
Ingo Molnar | e4d9191 | 2006-07-03 00:24:34 -0700 | [diff] [blame] | 94 | #define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init) |
| 95 | #define RW_LOCK_UNLOCKED __RW_LOCK_UNLOCKED(old_style_rw_init) |
| 96 | |
| 97 | #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) |
| 98 | #define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 99 | |
| 100 | #endif /* __LINUX_SPINLOCK_TYPES_H */ |