40 lines
697 B
C
40 lines
697 B
C
|
#include <stdint.h>
|
||
|
|
||
|
#include "atomic.h"
|
||
|
|
||
|
#include "rtos/context.h"
|
||
|
#include "rtos/spinlock.h"
|
||
|
|
||
|
void isr_spinlock_lock(struct spinlock *lock)
|
||
|
{
|
||
|
lock->priority_unlocked = current_context->priority;
|
||
|
current_context->priority = 0;
|
||
|
lock->locked = 1;
|
||
|
}
|
||
|
|
||
|
void spinlock_lock(struct spinlock *lock)
|
||
|
{
|
||
|
disable_irqs()
|
||
|
isr_spinlock_lock(lock);
|
||
|
restore_irqs();
|
||
|
}
|
||
|
|
||
|
void isr_spinlock_unlock(struct spinlock *lock)
|
||
|
{
|
||
|
current_context->priority = lock->priority_unlocked;
|
||
|
lock->locked = 0;
|
||
|
// TODO: check for context-switch...
|
||
|
}
|
||
|
|
||
|
void spinlock_unlock(struct spinlock *lock)
|
||
|
{
|
||
|
disable_irqs()
|
||
|
isr_spinlock_unlock(lock);
|
||
|
restore_irqs();
|
||
|
}
|
||
|
|
||
|
void spinlock_init(struct spinlock *lock)
|
||
|
{
|
||
|
lock->locked = 0;
|
||
|
}
|