Changes in kernel/generic/include/synch/spinlock.h [90c8b8d:98000fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/synch/spinlock.h
r90c8b8d r98000fb 43 43 44 44 #ifdef CONFIG_SMP 45 46 45 typedef struct { 47 atomic_t val;48 49 46 #ifdef CONFIG_DEBUG_SPINLOCK 50 47 char *name; 51 48 #endif 49 atomic_t val; 52 50 } spinlock_t; 53 51 … … 56 54 * where the lock gets initialized in run time. 57 55 */ 58 #define SPINLOCK_DECLARE( lock_name) spinlock_t lock_name59 #define SPINLOCK_EXTERN( lock_name) extern spinlock_t lock_name56 #define SPINLOCK_DECLARE(slname) spinlock_t slname 57 #define SPINLOCK_EXTERN(slname) extern spinlock_t slname 60 58 61 59 /* … … 64 62 */ 65 63 #ifdef CONFIG_DEBUG_SPINLOCK 66 67 #define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \ 68 spinlock_t lock_name = { \ 69 .name = desc_name, \ 70 .val = { 0 } \ 64 #define SPINLOCK_INITIALIZE(slname) \ 65 spinlock_t slname = { \ 66 .name = #slname, \ 67 .val = { 0 } \ 71 68 } 72 73 #define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \ 74 static spinlock_t lock_name = { \ 75 .name = desc_name, \ 76 .val = { 0 } \ 69 #else 70 #define SPINLOCK_INITIALIZE(slname) \ 71 spinlock_t slname = { \ 72 .val = { 0 } \ 77 73 } 78 79 #define spinlock_lock(lock) spinlock_lock_debug(lock)80 81 #else82 83 #define SPINLOCK_INITIALIZE_NAME(lock_name, desc_name) \84 spinlock_t lock_name = { \85 .val = { 0 } \86 }87 88 #define SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, desc_name) \89 static spinlock_t lock_name = { \90 .val = { 0 } \91 }92 93 #define spinlock_lock(lock) atomic_lock_arch(&(lock)->val)94 95 74 #endif 96 75 97 #define SPINLOCK_INITIALIZE(lock_name) \ 98 SPINLOCK_INITIALIZE_NAME(lock_name, #lock_name) 76 extern void spinlock_initialize(spinlock_t *sl, char *name); 77 extern int spinlock_trylock(spinlock_t *sl); 78 extern void spinlock_lock_debug(spinlock_t *sl); 99 79 100 #define SPINLOCK_STATIC_INITIALIZE(lock_name) \ 101 SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name) 102 103 extern void spinlock_initialize(spinlock_t *lock, char *name); 104 extern int spinlock_trylock(spinlock_t *lock); 105 extern void spinlock_lock_debug(spinlock_t *lock); 80 #ifdef CONFIG_DEBUG_SPINLOCK 81 # define spinlock_lock(x) spinlock_lock_debug(x) 82 #else 83 # define spinlock_lock(x) atomic_lock_arch(&(x)->val) 84 #endif 106 85 107 86 /** Unlock spinlock … … 111 90 * @param sl Pointer to spinlock_t structure. 112 91 */ 113 static inline void spinlock_unlock(spinlock_t * lock)92 static inline void spinlock_unlock(spinlock_t *sl) 114 93 { 115 ASSERT(atomic_get(& lock->val) != 0);116 94 ASSERT(atomic_get(&sl->val) != 0); 95 117 96 /* 118 97 * Prevent critical section code from bleeding out this way down. … … 120 99 CS_LEAVE_BARRIER(); 121 100 122 atomic_set(& lock->val, 0);101 atomic_set(&sl->val, 0); 123 102 preemption_enable(); 124 103 } … … 126 105 #ifdef CONFIG_DEBUG_SPINLOCK 127 106 128 #include <print.h> 107 extern int printf(const char *, ...); 129 108 130 #define DEADLOCK_THRESHOLD 100000000 131 132 #define DEADLOCK_PROBE_INIT(pname) size_t pname = 0 133 134 #define DEADLOCK_PROBE(pname, value) \ 135 if ((pname)++ > (value)) { \ 136 (pname) = 0; \ 137 printf("Deadlock probe %s: exceeded threshold %u\n", \ 138 "cpu%u: function=%s, line=%u\n", \ 139 #pname, (value), CPU->id, __func__, __LINE__); \ 109 #define DEADLOCK_THRESHOLD 100000000 110 #define DEADLOCK_PROBE_INIT(pname) size_t pname = 0 111 #define DEADLOCK_PROBE(pname, value) \ 112 if ((pname)++ > (value)) { \ 113 (pname) = 0; \ 114 printf("Deadlock probe %s: exceeded threshold %u\n", \ 115 "cpu%u: function=%s, line=%u\n", \ 116 #pname, (value), CPU->id, __func__, __LINE__); \ 140 117 } 118 #else 119 #define DEADLOCK_PROBE_INIT(pname) 120 #define DEADLOCK_PROBE(pname, value) 121 #endif 141 122 142 123 #else 143 124 144 #define DEADLOCK_PROBE_INIT(pname)145 #define DEADLOCK_PROBE(pname, value)146 147 #endif148 149 #else /* CONFIG_SMP */150 151 125 /* On UP systems, spinlocks are effectively left out. */ 152 153 126 #define SPINLOCK_DECLARE(name) 154 127 #define SPINLOCK_EXTERN(name) 128 #define SPINLOCK_INITIALIZE(name) 155 129 156 #define SPINLOCK_INITIALIZE(name) 157 #define SPINLOCK_STATIC_INITIALIZE(name) 158 159 #define SPINLOCK_INITIALIZE_NAME(name, desc_name) 160 #define SPINLOCK_STATIC_INITIALIZE_NAME(name, desc_name) 161 162 #define spinlock_initialize(lock, name) 163 164 #define spinlock_lock(lock) preemption_disable() 165 #define spinlock_trylock(lock) (preemption_disable(), 1) 166 #define spinlock_unlock(lock) preemption_enable() 130 #define spinlock_initialize(x, name) 131 #define spinlock_lock(x) preemption_disable() 132 #define spinlock_trylock(x) (preemption_disable(), 1) 133 #define spinlock_unlock(x) preemption_enable() 167 134 168 135 #define DEADLOCK_PROBE_INIT(pname)
Note:
See TracChangeset
for help on using the changeset viewer.