1 #ifndef __LINUX_SPINLOCK_TYPES_H
2 #define __LINUX_SPINLOCK_TYPES_H
5 * include/linux/spinlock_types.h - generic spinlock type definitions
8 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
9 * Released under the General Public License (GPL).
12 #if defined(CONFIG_SMP)
13 # include <asm/spinlock_types.h>
15 # include <linux/spinlock_types_up.h>
18 #include <linux/lockdep.h>
20 typedef struct raw_spinlock
{
21 arch_spinlock_t raw_lock
;
22 #ifdef CONFIG_DEBUG_SPINLOCK
23 unsigned int magic
, owner_cpu
;
26 #ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map
;
31 #define SPINLOCK_MAGIC 0xdead4ead
33 #define SPINLOCK_OWNER_INIT ((void *)-1L)
35 #ifdef CONFIG_DEBUG_LOCK_ALLOC
36 # define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
38 # define SPIN_DEP_MAP_INIT(lockname)
41 #ifdef CONFIG_DEBUG_SPINLOCK
42 # define SPIN_DEBUG_INIT(lockname) \
43 .magic = SPINLOCK_MAGIC, \
45 .owner = SPINLOCK_OWNER_INIT,
47 # define SPIN_DEBUG_INIT(lockname)
50 #define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
52 .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
53 SPIN_DEBUG_INIT(lockname) \
54 SPIN_DEP_MAP_INIT(lockname) }
56 #define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
57 (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
59 #define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
61 typedef struct spinlock
{
63 struct raw_spinlock rlock
;
65 #ifdef CONFIG_DEBUG_LOCK_ALLOC
66 # define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
68 u8 __padding
[LOCK_PADSIZE
];
69 struct lockdep_map dep_map
;
75 #define __SPIN_LOCK_INITIALIZER(lockname) \
76 { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
78 #define __SPIN_LOCK_UNLOCKED(lockname) \
79 (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
81 #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
83 #include <linux/rwlock_types.h>
85 #endif /* __LINUX_SPINLOCK_TYPES_H */