Commit | Line | Data |
---|---|---|
fb1c8f93 IM |
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 | ||
21f8ca3b PZ |
18 | #include <linux/lockdep.h> |
19 | ||
c2f21ce2 | 20 | typedef struct raw_spinlock { |
445c8951 | 21 | arch_spinlock_t raw_lock; |
fb1c8f93 IM |
22 | #ifdef CONFIG_DEBUG_SPINLOCK |
23 | unsigned int magic, owner_cpu; | |
24 | void *owner; | |
25 | #endif | |
8a25d5de IM |
26 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
27 | struct lockdep_map dep_map; | |
28 | #endif | |
c2f21ce2 | 29 | } raw_spinlock_t; |
fb1c8f93 IM |
30 | |
31 | #define SPINLOCK_MAGIC 0xdead4ead | |
32 | ||
fb1c8f93 IM |
33 | #define SPINLOCK_OWNER_INIT ((void *)-1L) |
34 | ||
8a25d5de | 35 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
de8f5e4f PZ |
36 | # define RAW_SPIN_DEP_MAP_INIT(lockname) \ |
37 | .dep_map = { \ | |
38 | .name = #lockname, \ | |
39 | .wait_type_inner = LD_WAIT_SPIN, \ | |
40 | } | |
41 | # define SPIN_DEP_MAP_INIT(lockname) \ | |
42 | .dep_map = { \ | |
43 | .name = #lockname, \ | |
44 | .wait_type_inner = LD_WAIT_CONFIG, \ | |
45 | } | |
8a25d5de | 46 | #else |
de8f5e4f | 47 | # define RAW_SPIN_DEP_MAP_INIT(lockname) |
8a25d5de IM |
48 | # define SPIN_DEP_MAP_INIT(lockname) |
49 | #endif | |
50 | ||
fb1c8f93 | 51 | #ifdef CONFIG_DEBUG_SPINLOCK |
c2f21ce2 TG |
52 | # define SPIN_DEBUG_INIT(lockname) \ |
53 | .magic = SPINLOCK_MAGIC, \ | |
54 | .owner_cpu = -1, \ | |
55 | .owner = SPINLOCK_OWNER_INIT, | |
fb1c8f93 | 56 | #else |
c2f21ce2 | 57 | # define SPIN_DEBUG_INIT(lockname) |
fb1c8f93 IM |
58 | #endif |
59 | ||
c2f21ce2 TG |
60 | #define __RAW_SPIN_LOCK_INITIALIZER(lockname) \ |
61 | { \ | |
62 | .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \ | |
63 | SPIN_DEBUG_INIT(lockname) \ | |
de8f5e4f | 64 | RAW_SPIN_DEP_MAP_INIT(lockname) } |
c2f21ce2 TG |
65 | |
66 | #define __RAW_SPIN_LOCK_UNLOCKED(lockname) \ | |
67 | (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname) | |
68 | ||
69 | #define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x) | |
70 | ||
71 | typedef struct spinlock { | |
72 | union { | |
73 | struct raw_spinlock rlock; | |
74 | ||
75 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | |
76 | # define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map)) | |
77 | struct { | |
78 | u8 __padding[LOCK_PADSIZE]; | |
79 | struct lockdep_map dep_map; | |
80 | }; | |
81 | #endif | |
82 | }; | |
83 | } spinlock_t; | |
84 | ||
de8f5e4f PZ |
85 | #define ___SPIN_LOCK_INITIALIZER(lockname) \ |
86 | { \ | |
87 | .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \ | |
88 | SPIN_DEBUG_INIT(lockname) \ | |
89 | SPIN_DEP_MAP_INIT(lockname) } | |
90 | ||
c2f21ce2 | 91 | #define __SPIN_LOCK_INITIALIZER(lockname) \ |
de8f5e4f | 92 | { { .rlock = ___SPIN_LOCK_INITIALIZER(lockname) } } |
c2f21ce2 TG |
93 | |
94 | #define __SPIN_LOCK_UNLOCKED(lockname) \ | |
de8f5e4f | 95 | (spinlock_t) __SPIN_LOCK_INITIALIZER(lockname) |
c2f21ce2 | 96 | |
e4d91918 | 97 | #define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x) |
ef12f109 TG |
98 | |
99 | #include <linux/rwlock_types.h> | |
fb1c8f93 IM |
100 | |
101 | #endif /* __LINUX_SPINLOCK_TYPES_H */ |