disable interrupts while locked
This commit is contained in:
parent
bf16ead21f
commit
43f23cd7a2
1 changed files with 3 additions and 1 deletions
|
|
@ -1,11 +1,13 @@
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
|
|
||||||
void spin_lock(struct spinlock *s) {
|
void spin_lock(struct spinlock *s) {
|
||||||
|
__asm__ ("cli" :: );
|
||||||
while (atomic_exchange_explicit(&s->lock, 1, memory_order_acquire)) {
|
while (atomic_exchange_explicit(&s->lock, 1, memory_order_acquire)) {
|
||||||
// spin
|
__asm__ ("pause" :: );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void spin_unlock(struct spinlock *s) {
|
void spin_unlock(struct spinlock *s) {
|
||||||
atomic_store_explicit(&s->lock, 0, memory_order_release);
|
atomic_store_explicit(&s->lock, 0, memory_order_release);
|
||||||
|
__asm__ ("sti" :: );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue