X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdevices%2Ftimer.c;h=9c611a1d3eda68b6fd2317304faaef9381f9eb40;hb=a23e3e47eb037b5de510b9661635e3df0a5bfdd0;hp=8f4838f048e04ec80d0060fc10cd1a3d77da3216;hpb=275c68384d654e4c1f9ac4a3eadd2c3d4e46cf86;p=pintos-anon diff --git a/src/devices/timer.c b/src/devices/timer.c index 8f4838f..9c611a1 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 @@ -20,7 +21,7 @@ static volatile int64_t ticks; static intr_handler_func timer_interrupt; -/* Sets up the 8254 Programmable Interrupt Timer (PIT) to +/* Sets up the 8254 Programmable Interval Timer (PIT) to interrupt PIT_FREQ times per second, and registers the corresponding interrupt. */ void @@ -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. */