uint32_t thread_stack_ofs = offsetof (struct thread, stack);
static struct list run_queue;
+static struct thread *idle_thread;
+
+static void
+idle (void *aux UNUSED)
+{
+ for (;;)
+ {
+ /* Wait for an interrupt. */
+ asm ("hlt");
+
+ /* Let someone else run. */
+ intr_disable ();
+ thread_sleep ();
+ intr_enable ();
+ }
+}
void
thread_init (void)
{
list_init (&run_queue);
+ idle_thread = thread_create ("idle", idle, NULL);
}
struct thread_root_frame
thread_root (void (*function) (void *aux), void *aux)
{
ASSERT (function != NULL);
-
+
+ intr_enable ();
function (aux);
thread_exit ();
}
return list_entry (list_pop_front (&run_queue), struct thread, rq_elem);
}
-static void
-idle (void)
-{
- static int idle = 0;
- if (idle++ == 0)
- printk ("idle\n");
-}
-
void
thread_destroy (struct thread *t)
{
void
schedule_tail (struct thread *prev)
{
+#ifdef USERPROG
struct thread *cur = thread_current ();
+#endif
ASSERT (intr_get_level () == IF_OFF);
cur = thread_current ();
ASSERT (cur->status != THREAD_RUNNING);
- while ((next = find_next_to_run ()) == NULL)
- idle ();
+ next = find_next_to_run ();
+ if (next == NULL)
+ next = idle_thread;
next->status = THREAD_RUNNING;
if (cur != next)
list_remove (&t->rq_elem);
t->status = THREAD_RUNNING;
switch_threads (NULL, t);
+ NOT_REACHED ();
}
void