Changes in kernel/generic/src/synch/spinlock.c [78de83de:05882233] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/spinlock.c
r78de83de r05882233 56 56 void spinlock_initialize(spinlock_t *lock, const char *name) 57 57 { 58 atomic_ flag_clear_explicit(&lock->flag, memory_order_relaxed);58 atomic_set(&lock->val, 0); 59 59 #ifdef CONFIG_DEBUG_SPINLOCK 60 60 lock->name = name; … … 79 79 80 80 preemption_disable(); 81 while ( atomic_flag_test_and_set_explicit(&lock->flag, memory_order_acquire)) {81 while (test_and_set(&lock->val)) { 82 82 /* 83 83 * We need to be careful about particular locks … … 115 115 if (deadlock_reported) 116 116 printf("cpu%u: not deadlocked\n", CPU->id); 117 118 /* 119 * Prevent critical section code from bleeding out this way up. 120 */ 121 CS_ENTER_BARRIER(); 117 122 } 118 123 … … 127 132 ASSERT_SPINLOCK(spinlock_locked(lock), lock); 128 133 129 atomic_flag_clear_explicit(&lock->flag, memory_order_release); 134 /* 135 * Prevent critical section code from bleeding out this way down. 136 */ 137 CS_LEAVE_BARRIER(); 138 139 atomic_set(&lock->val, 0); 130 140 preemption_enable(); 131 141 } … … 146 156 { 147 157 preemption_disable(); 148 bool ret = !atomic_flag_test_and_set_explicit(&lock->flag, memory_order_acquire); 158 bool ret = !test_and_set(&lock->val); 159 160 /* 161 * Prevent critical section code from bleeding out this way up. 162 */ 163 CS_ENTER_BARRIER(); 149 164 150 165 if (!ret) … … 161 176 bool spinlock_locked(spinlock_t *lock) 162 177 { 163 // XXX: Atomic flag doesn't support simple atomic read (by design), 164 // so instead we test_and_set and then clear if necessary. 165 // This function is only used inside assert, so we don't need 166 // any preemption_disable/enable here. 167 168 bool ret = atomic_flag_test_and_set_explicit(&lock->flag, memory_order_relaxed); 169 if (!ret) 170 atomic_flag_clear_explicit(&lock->flag, memory_order_relaxed); 171 return ret; 178 return atomic_get(&lock->val) != 0; 172 179 } 173 180
Note:
See TracChangeset
for help on using the changeset viewer.