summaryrefslogtreecommitdiffstats
path: root/src/devices/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/timer.c')
-rw-r--r--src/devices/timer.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/devices/timer.c b/src/devices/timer.c
index 856a14e..aea6aa2 100644
--- a/src/devices/timer.c
+++ b/src/devices/timer.c
@@ -114,6 +114,9 @@ timer_sleep (int64_t ticks)
new_waiting_thread.tick_target = start + ticks;
sema_init (&new_waiting_thread.sema, 0);
+ // disable interrupts so the timer interrupt handler can't modify the list
+ enum intr_level old_level = intr_disable ();
+
struct list_elem *before = list_begin (&waiting_threads);
while (before != list_end (&waiting_threads)) {
struct list_elem *next = list_next (before);
@@ -125,6 +128,8 @@ timer_sleep (int64_t ticks)
}
list_insert (before, &new_waiting_thread.elem);
+ intr_set_level (old_level);
+
sema_down (&new_waiting_thread.sema);
}