Changeset 4777e02 in mainline
- Timestamp:
- 2023-02-12T22:25:23Z (21 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c7326f21
- Parents:
- 111b9b9
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-12 22:11:54)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-12 22:25:23)
- Location:
- kernel/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/synch/spinlock.h
r111b9b9 r4777e02 117 117 SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name) 118 118 119 #ifdef CONFIG_SMP 120 119 121 extern void spinlock_initialize(spinlock_t *, const char *); 120 122 extern bool spinlock_trylock(spinlock_t *); … … 122 124 extern void spinlock_unlock(spinlock_t *); 123 125 extern bool spinlock_locked(spinlock_t *); 126 127 #else 128 129 #include <preemption.h> 130 131 static inline void spinlock_initialize(spinlock_t *l, const char *name) 132 { 133 } 134 135 static inline bool spinlock_trylock(spinlock_t *l) 136 { 137 return true; 138 } 139 140 static inline void spinlock_lock(spinlock_t *l) 141 { 142 preemption_disable(); 143 } 144 145 static inline void spinlock_unlock(spinlock_t *l) 146 { 147 preemption_enable(); 148 } 149 150 static inline bool spinlock_locked(spinlock_t *l) 151 { 152 return true; 153 } 154 155 #endif 124 156 125 157 typedef struct { -
kernel/generic/src/synch/spinlock.c
r111b9b9 r4777e02 37 37 */ 38 38 39 #ifdef CONFIG_SMP 40 39 41 #include <arch/asm.h> 40 42 #include <synch/spinlock.h> … … 56 58 void spinlock_initialize(spinlock_t *lock, const char *name) 57 59 { 58 #ifdef CONFIG_SMP59 60 atomic_flag_clear_explicit(&lock->flag, memory_order_relaxed); 60 61 #ifdef CONFIG_DEBUG_SPINLOCK 61 62 lock->name = name; 62 #endif63 63 #endif 64 64 } … … 73 73 preemption_disable(); 74 74 75 #ifdef CONFIG_SMP76 75 bool deadlock_reported = false; 77 76 size_t i = 0; … … 120 119 if (deadlock_reported) 121 120 printf("cpu%u: not deadlocked\n", CPU->id); 122 123 #endif124 121 } 125 122 … … 130 127 void spinlock_unlock(spinlock_t *lock) 131 128 { 132 #ifdef CONFIG_SMP133 129 #ifdef CONFIG_DEBUG_SPINLOCK 134 130 ASSERT_SPINLOCK(spinlock_locked(lock), lock); … … 136 132 137 133 atomic_flag_clear_explicit(&lock->flag, memory_order_release); 138 #endif139 140 134 preemption_enable(); 141 135 } … … 154 148 preemption_disable(); 155 149 156 #ifdef CONFIG_SMP157 150 bool ret = !atomic_flag_test_and_set_explicit(&lock->flag, memory_order_acquire); 158 151 … … 161 154 162 155 return ret; 163 #else164 return true;165 #endif166 156 } 167 157 … … 173 163 bool spinlock_locked(spinlock_t *lock) 174 164 { 175 #ifdef CONFIG_SMP176 165 // NOTE: Atomic flag doesn't support simple atomic read (by design), 177 166 // so instead we test_and_set and then clear if necessary. … … 183 172 atomic_flag_clear_explicit(&lock->flag, memory_order_relaxed); 184 173 return ret; 185 #else186 return true;187 #endif188 174 } 175 176 #endif /* CONFIG_SMP */ 189 177 190 178 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.