lock irqs in spinlock
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#include <zinnia/irq.h>
|
||||||
#include <zinnia/spin.h>
|
#include <zinnia/spin.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ void spin_init(struct spinlock* spin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void spin_lock(struct spinlock* spin) {
|
void spin_lock(struct spinlock* spin) {
|
||||||
|
irq_lock();
|
||||||
uint32_t my = atomic_fetch_add_explicit(&spin->next, 1, memory_order_relaxed);
|
uint32_t my = atomic_fetch_add_explicit(&spin->next, 1, memory_order_relaxed);
|
||||||
|
|
||||||
while (atomic_load_explicit(&spin->owner, memory_order_acquire) != my) {
|
while (atomic_load_explicit(&spin->owner, memory_order_acquire) != my) {
|
||||||
@@ -17,4 +19,5 @@ void spin_lock(struct spinlock* spin) {
|
|||||||
void spin_unlock(struct spinlock* spin) {
|
void spin_unlock(struct spinlock* spin) {
|
||||||
uint32_t val = atomic_load_explicit(&spin->owner, memory_order_relaxed);
|
uint32_t val = atomic_load_explicit(&spin->owner, memory_order_relaxed);
|
||||||
atomic_store_explicit(&spin->owner, val + 1, memory_order_release);
|
atomic_store_explicit(&spin->owner, val + 1, memory_order_release);
|
||||||
|
irq_unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user