+
+/* Schedules a new process. At entry, interrupts must be off and
+ the running process's state must have been changed from
+ running to some other state. This function finds another
+ thread to run and switches to it. */
+static void
+schedule (void)
+{
+ struct thread *cur = running_thread ();
+ struct thread *next = next_thread_to_run ();
+ struct thread *prev = NULL;
+
+ ASSERT (intr_get_level () == INTR_OFF);
+ ASSERT (cur->status != THREAD_RUNNING);
+ ASSERT (is_thread (next));
+
+ if (cur != next)
+ prev = switch_threads (cur, next);
+ schedule_tail (prev);
+}
+
+/* Returns a tid to use for a new thread. */
+static tid_t
+allocate_tid (void)
+{
+ static tid_t next_tid = 1;
+ tid_t tid;
+
+ lock_acquire (&tid_lock);
+ tid = next_tid++;
+ lock_release (&tid_lock);
+
+ return tid;
+}
+\f
+/* Offset of `stack' member within `struct thread'.
+ Used by switch.S, which can't figure it out on its own. */
+uint32_t thread_stack_ofs = offsetof (struct thread, stack);