From 208fb587faa75eaa0e740db9b605ff3d7ba24905 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 11 Sep 2004 23:16:45 +0000 Subject: [PATCH] Call thread_yield() in timer_sleep() if interrupts are on. --- src/devices/timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/devices/timer.c b/src/devices/timer.c index 8f4838f..200d58f 100644 --- a/src/devices/timer.c +++ b/src/devices/timer.c @@ -3,6 +3,7 @@ #include #include "threads/interrupt.h" #include "threads/io.h" +#include "threads/thread.h" #if TIMER_FREQ < 19 #error 8254 timer requires TIMER_FREQ >= 19 @@ -55,14 +56,15 @@ timer_elapsed (int64_t then) return timer_ticks () - then; } -/* Suspends executions for approximately TICKS timer ticks. */ +/* Suspends execution for approximately TICKS timer ticks. */ void timer_sleep (int64_t ticks) { int64_t start = timer_ticks (); while (timer_elapsed (start) < ticks) - continue; + if (intr_get_level () == INTR_ON) + thread_yield (); } /* Returns MS milliseconds in timer ticks, rounding up. */ -- 2.30.2