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 18 #include <linux/lockdep.h> 19 20 typedef struct raw_spinlock { 21 arch_spinlock_t raw_lock; 22 #ifdef CONFIG_DEBUG_SPINLOCK 23 unsigned int magic, owner_cpu; 24 void *owner; 25 #endif 26 #ifdef CONFIG_DEBUG_LOCK_ALLOC 27 struct lockdep_map dep_map; 28 #endif 29 } raw_spinlock_t; 30 31 #define SPINLOCK_MAGIC 0xdead4ead 32 33 #define SPINLOCK_OWNER_INIT ((void *)-1L) 34 35 #ifdef CONFIG_DEBUG_LOCK_ALLOC 36 # define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname } 37 #else 38 # define SPIN_DEP_MAP_INIT(lockname) 39 #endif 40 41 #ifdef CONFIG_DEBUG_SPINLOCK 42 # define SPIN_DEBUG_INIT(lockname) \ 43 .magic = SPINLOCK_MAGIC, \ 44 .owner_cpu = -1, \ 45 .owner = SPINLOCK_OWNER_INIT, 46 #else 47 # define SPIN_DEBUG_INIT(lockname) 48 #endif 49 50 #define __RAW_SPIN_LOCK_INITIALIZER(lockname) \ 51 { \ 52 .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \ 53 SPIN_DEBUG_INIT(lockname) \ 54 SPIN_DEP_MAP_INIT(lockname) } 55 56 #define __RAW_SPIN_LOCK_UNLOCKED(lockname) \ 57 (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname) 58 59 #define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x) 60 61 typedef struct spinlock { 62 union { 63 struct raw_spinlock rlock; 64 65 #ifdef CONFIG_DEBUG_LOCK_ALLOC 66 # define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map)) 67 struct { 68 u8 __padding[LOCK_PADSIZE]; 69 struct lockdep_map dep_map; 70 }; 71 #endif 72 }; 73 } spinlock_t; 74 75 #define __SPIN_LOCK_INITIALIZER(lockname) \ 76 { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } } 77 78 #define __SPIN_LOCK_UNLOCKED(lockname) \ 79 (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname) 80 81 #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) 82 83 #include <linux/rwlock_types.h> 84 85 #endif /* __LINUX_SPINLOCK_TYPES_H */ 86