schedule ();
intr_set_level (old_level);
}
+
+/* Sets the current thread's priority to NEW_PRIORITY. */
+void
+thread_set_priority (int new_priority)
+{
+ thread_current ()->priority = new_priority;
+}
+
+/* Returns the current thread's priority. */
+int
+thread_get_priority (void)
+{
+ return thread_current ()->priority;
+}
\f
/* Idle thread. Executes when no other thread is ready to run. */
static void
/* Let someone else run. */
intr_disable ();
thread_block ();
- intr_enable ();
- /* Use CPU `hlt' instruction to wait for interrupt.
- See [IA32-v2a] "HLT" and [IA32-v3] 7.7. */
- asm ("hlt");
+ /* Re-enable interrupts and wait for the next one.
+
+ The `sti' instruction disables interrupts until the
+ completion of the next instruction, so these two
+ instructions are executed atomically. This atomicity is
+ important; otherwise, an interrupt could be handled
+ between re-enabling interrupts and waiting for the next
+ one to occur, wasting as much as one clock tick worth of
+ time.
+
+ See [IA32-v2a] "HLT", [IA32-v2b] "STI", and [IA32-v3] 7.7. */
+ asm ("sti; hlt");
}
}