#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
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
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. */