disable interrupts when holding kernel lock
This commit is contained in:
parent
bd303ed060
commit
f7cea12b38
3 changed files with 10 additions and 0 deletions
1
defs.h
1
defs.h
|
@ -41,6 +41,7 @@ void lapic_init(int);
|
|||
void lapic_timerinit(void);
|
||||
void lapic_timerintr(void);
|
||||
void lapic_enableintr(void);
|
||||
void lapic_disableintr(void);
|
||||
|
||||
// spinlock.c
|
||||
extern uint32_t kernel_lock;
|
||||
|
|
6
mp.c
6
mp.c
|
@ -183,6 +183,12 @@ lapic_enableintr(void)
|
|||
lapic_write(LAPIC_TPR, 0);
|
||||
}
|
||||
|
||||
void
|
||||
lapic_disableintr(void)
|
||||
{
|
||||
lapic_write(LAPIC_TPR, 0xFF);
|
||||
}
|
||||
|
||||
int
|
||||
cpu(void)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,8 @@ acquire_spinlock(uint32_t* lock)
|
|||
|
||||
if (*lock == cpu_id)
|
||||
return;
|
||||
|
||||
lapic_disableintr();
|
||||
while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; }
|
||||
// cprintf ("acquired: %d\n", cpu_id);
|
||||
}
|
||||
|
@ -26,6 +28,7 @@ release_spinlock(uint32_t* lock)
|
|||
if (*lock != cpu_id)
|
||||
panic("release_spinlock: releasing a lock that i don't own\n");
|
||||
*lock = LOCK_FREE;
|
||||
lapic_enableintr();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue