[go: nahoru, domu]

Skip to content

Commit

Permalink
disable irq line during interrupt handler to avoid race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Dec 21, 2021
1 parent d20157d commit d64a0c9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/kernel/interrupt/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include "kernel/debug/coredump.h"
#include "kernel/device/keyboard.h"
#include "kernel/arch/pit.h"
#include "kernel/arch/pic.h"
#include "kernel/interrupt/spurious.h"
#include "kernel/task/scheduler.h"


/*
* Notes to myself:
*
Expand Down Expand Up @@ -191,13 +193,18 @@ void interrupt_handler(interrupt_stack_frame_t *int_frame) {
/* spurious interrupt */
if (int_frame->trap_number == 39) {
/* there is nothing to be done here... let's carry on with our lives */
pic_mask_irq(PIC_LPT1_OR_SPURIOUS_INTERRUPT);
spurious_handle_irq();
pic_unmask_irq(PIC_LPT1_OR_SPURIOUS_INTERRUPT);
} else if (int_frame->trap_number == 32) {
pic_mask_irq(PIC_PROG_INT_TIMER_INTERRUPT);
/* PIT is expected to send EOI */
pit_timer_handle_irq();
} else if (int_frame->trap_number == 33) {
pic_unmask_irq(PIC_KEYBOARD_INTERRUPT);
/* keyboard is expected to send EOI */
keyboard_handle_irq();
pic_unmask_irq(PIC_KEYBOARD_INTERRUPT);
} else {
/* disable interrupts and hang the system */
disable_interrupts();
Expand All @@ -210,9 +217,12 @@ void interrupt_handler(interrupt_stack_frame_t *int_frame) {
}
}

/* check if there are peding tasks such as scheduling to be done before returning */
if(int_frame->trap_number == 32 && this_rq()->need_resched){
schedule(int_frame);
/* check if there are peding tasks such as scheduling to be done before returning */
if (int_frame->trap_number == 32) {
if (this_rq()->need_resched)
schedule(int_frame);

pic_unmask_irq(PIC_PROG_INT_TIMER_INTERRUPT);
}

}
Expand Down

0 comments on commit d64a0c9

Please sign in to comment.