Spinlock fix small race window
This commit is contained in:
@ -17,7 +17,7 @@ void spinlock_init(SpinLock *sl) {
|
|||||||
|
|
||||||
uint64_t irqsave(void) {
|
uint64_t irqsave(void) {
|
||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
asm volatile("pushfq; cli; popq %0" : "=r"(flags) :: "memory", "cc");
|
asm volatile("pushfq; popq %0; cli" : "=r"(flags) :: "memory", "cc");
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ void irqrestore_nested(void) {
|
|||||||
|
|
||||||
void spinlock_acquire(SpinLock *sl) {
|
void spinlock_acquire(SpinLock *sl) {
|
||||||
irqsave_nested();
|
irqsave_nested();
|
||||||
|
|
||||||
while (atomic_test_and_set_explicit(&sl->lock, memory_order_acquire)) {
|
while (atomic_test_and_set_explicit(&sl->lock, memory_order_acquire)) {
|
||||||
SPINLOCK_HINT();
|
SPINLOCK_HINT();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user