7 Scheduler::Scheduler() :
13 * Add a Thread to the scheduler's ready list.
14 * @param t The Thread to add
16 void Scheduler::add_thread(Thread *t)
18 DEBUG("thread %d\n", t->get_id());
19 readyList.push_back(t);
23 * Remove a given Thread from the scheduler.
24 * @param t The Thread to remove
26 void Scheduler::remove_thread(Thread *t)
35 * Force one Thread to wait on another Thread. The "join" Thread should
36 * eventually wake up the waiting Thread via Scheduler::wake.
37 * @param wait The Thread that should wait
38 * @param join The Thread on which we are waiting.
40 void Scheduler::wait(Thread *wait, Thread *join)
42 ASSERT(!join->is_complete());
44 join->push_wait_list(wait);
45 wait->set_state(THREAD_BLOCKED);
49 * Prevent a Thread from being scheduled. The sleeping Thread should be
50 * re-awoken via Scheduler::wake.
51 * @param thread The Thread that should sleep
53 void Scheduler::sleep(Thread *t)
56 t->set_state(THREAD_BLOCKED);
60 * Wake a Thread up that was previously waiting (see Scheduler::wait)
61 * @param t The Thread to wake up
63 void Scheduler::wake(Thread *t)
66 t->set_state(THREAD_READY);
70 * Remove one Thread from the scheduler. This implementation defaults to FIFO,
71 * if a thread is not already provided.
73 * @param t Thread to run, if chosen by an external entity (e.g.,
74 * ModelChecker). May be NULL to indicate no external choice.
75 * @return The next Thread to run
77 Thread * Scheduler::next_thread(Thread *t)
82 } else if (readyList.empty()) {
85 t = readyList.front();
87 readyList.pop_front();
96 * @return The currently-running Thread
98 Thread * Scheduler::get_current_thread() const
104 * Print debugging information about the current state of the scheduler. Only
105 * prints something if debugging is enabled.
107 void Scheduler::print() const
110 DEBUG("Current thread: %d\n", current->get_id());
112 DEBUG("No current thread\n");
113 DEBUG("Num. threads in ready list: %zu\n", readyList.size());
115 std::list<Thread *, MyAlloc< Thread * > >::const_iterator it;
116 for (it = readyList.begin(); it != readyList.end(); it++)
117 DEBUG("In ready list: thread %d\n", (*it)->get_id());