Skip to content

Commit 17e7997

Browse files
committed
spinlock: try lock for use in interrupt
Signed-off-by: Sandro Rüegge <[email protected]>
1 parent 1311614 commit 17e7997

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/spinlock.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ typedef volatile unsigned int spinlock_t;
3737

3838
/* Static declarations */
3939

40+
static inline bool spin_try_lock(spinlock_t *lock) {
41+
ASSERT(lock);
42+
return atomic_test_and_set_bit(LOCK_BIT, lock);
43+
}
44+
4045
static inline void spin_lock(spinlock_t *lock) {
4146
ASSERT(lock);
42-
while (atomic_test_and_set_bit(LOCK_BIT, lock))
47+
while (spin_try_lock(lock))
4348
cpu_relax();
4449
}
4550

0 commit comments

Comments
 (0)