Skip to content
Snippets Groups Projects
Commit 2c6a053e authored by Avi Kivity's avatar Avi Kivity
Browse files

sched: disable interrupts while taking a spinlock

Preemption with a spinlock taken would lead to deadlock, so prevent it
by disabling interrupts.
parent 21db6f2d
No related branches found
No related tags found
No related merge requests found
#include "mutex.hh"
#include <sched.hh>
#include "arch.hh"
struct waiter {
struct waiter* next;
......@@ -9,6 +10,7 @@ struct waiter {
extern "C" void spin_lock(spinlock_t *sl)
{
arch::irq_disable();
while (__sync_lock_test_and_set(&sl->lock, 1))
;
}
......@@ -16,6 +18,7 @@ extern "C" void spin_lock(spinlock_t *sl)
extern "C" void spin_unlock(spinlock_t *sl)
{
__sync_lock_release(&sl->lock, 0);
arch::irq_enable();
}
extern "C" void mutex_lock(mutex_t *mutex)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment