Comments.
[pintos-anon] / src / devices / timer.c
index 8f4838f048e04ec80d0060fc10cd1a3d77da3216..9c611a1d3eda68b6fd2317304faaef9381f9eb40 100644 (file)
@@ -3,6 +3,7 @@
 #include <round.h>
 #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. */