disable interrupts when holding kernel lock

This commit is contained in:
kaashoek 2006-06-28 16:44:41 +00:00
parent bd303ed060
commit f7cea12b38
3 changed files with 10 additions and 0 deletions

1
defs.h
View file

@ -41,6 +41,7 @@ void lapic_init(int);
void lapic_timerinit(void); void lapic_timerinit(void);
void lapic_timerintr(void); void lapic_timerintr(void);
void lapic_enableintr(void); void lapic_enableintr(void);
void lapic_disableintr(void);
// spinlock.c // spinlock.c
extern uint32_t kernel_lock; extern uint32_t kernel_lock;

6
mp.c
View file

@ -183,6 +183,12 @@ lapic_enableintr(void)
lapic_write(LAPIC_TPR, 0); lapic_write(LAPIC_TPR, 0);
} }
void
lapic_disableintr(void)
{
lapic_write(LAPIC_TPR, 0xFF);
}
int int
cpu(void) cpu(void)
{ {

View file

@ -14,6 +14,8 @@ acquire_spinlock(uint32_t* lock)
if (*lock == cpu_id) if (*lock == cpu_id)
return; return;
lapic_disableintr();
while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; } while ( cmpxchg(LOCK_FREE, cpu_id, lock) != cpu_id ) { ; }
// cprintf ("acquired: %d\n", cpu_id); // cprintf ("acquired: %d\n", cpu_id);
} }
@ -26,6 +28,7 @@ release_spinlock(uint32_t* lock)
if (*lock != cpu_id) if (*lock != cpu_id)
panic("release_spinlock: releasing a lock that i don't own\n"); panic("release_spinlock: releasing a lock that i don't own\n");
*lock = LOCK_FREE; *lock = LOCK_FREE;
lapic_enableintr();
} }
void void