sf->eip = switch_entry;
/* Add to run queue. */
- thread_wake (t);
+ thread_unblock (t);
return t;
}
sf->eip = switch_entry;
/* Add to run queue. */
- thread_wake (t);
+ thread_unblock (t);
return true;
}
#endif
-/* Transitions T from its current state to THREAD_READY, the
- ready-to-run state. On entry, T must be ready or blocked.
+/* Transitions a blocked thread T from its current state to the
+ ready-to-run state. If T is not blocked, there is no effect.
(Use thread_yield() to make the running thread ready.) */
void
-thread_wake (struct thread *t)
+thread_unblock (struct thread *t)
{
+ enum intr_level old_level;
+
ASSERT (is_thread (t));
- ASSERT (t->status == THREAD_READY || t->status == THREAD_BLOCKED);
- if (t->status != THREAD_READY)
+
+ old_level = intr_disable ();
+ if (t->status == THREAD_BLOCKED)
{
list_push_back (&run_queue, &t->rq_elem);
t->status = THREAD_READY;
}
+ intr_set_level (old_level);
}
/* Returns the name of thread T. */
}
/* Puts the current thread to sleep. It will not be scheduled
- again until awoken by thread_wake(). */
+ again until awoken by thread_unblock(). */
void
-thread_sleep (void)
+thread_block (void)
{
ASSERT (!intr_context ());
ASSERT (intr_get_level () == INTR_OFF);
/* Let someone else run. */
intr_disable ();
- thread_sleep ();
+ thread_block ();
intr_enable ();
}
}
ASSERT (intr_get_level () == INTR_OFF);
cur->status = THREAD_RUNNING;
- if (prev != NULL && prev->status == THREAD_DYING)
- destroy_thread (prev);
#ifdef USERPROG
addrspace_activate (cur);
#endif
+
+ if (prev != NULL && prev->status == THREAD_DYING)
+ destroy_thread (prev);
}
/* Schedules a new process. At entry, interrupts must be off and