break;
}
case THREAD_JOIN: {
- Thread *wait, *join;
- wait = get_thread(curr);
- join = (Thread *)curr->get_location();
- if (!join->is_complete())
- scheduler->wait(wait, join);
+ Thread *waiting, *blocking;
+ waiting = get_thread(curr);
+ blocking = (Thread *)curr->get_location();
+ if (!blocking->is_complete()) {
+ blocking->push_wait_list(curr);
+ scheduler->sleep(waiting);
+ }
break;
}
case THREAD_FINISH: {
Thread *th = get_thread(curr);
while (!th->wait_list_empty()) {
- Thread *wake = th->pop_wait_list();
+ ModelAction *act = th->pop_wait_list();
+ Thread *wake = get_thread(act);
scheduler->wake(wake);
}
th->complete();
readyList.remove(t);
}
-/**
- * Force one Thread to wait on another Thread. The "join" Thread should
- * eventually wake up the waiting Thread via Scheduler::wake.
- * @param wait The Thread that should wait
- * @param join The Thread on which we are waiting.
- */
-void Scheduler::wait(Thread *wait, Thread *join)
-{
- ASSERT(!join->is_complete());
- remove_thread(wait);
- join->push_wait_list(wait);
- wait->set_state(THREAD_BLOCKED);
-}
-
/**
* Prevent a Thread from being scheduled. The sleeping Thread should be
* re-awoken via Scheduler::wake.
Scheduler();
void add_thread(Thread *t);
void remove_thread(Thread *t);
- void wait(Thread *wait, Thread *join);
void sleep(Thread *t);
void wake(Thread *t);
Thread * next_thread(Thread *t);
bool wait_list_empty() { return wait_list.empty(); }
/**
- * Add a thread to the waiting list for this thread.
- * @param t The Thread to add
+ * Add a ModelAction to the waiting list for this thread.
+ * @param t The ModelAction to add. Must be a JOIN.
*/
- void push_wait_list(Thread *t) { wait_list.push_back(t); }
+ void push_wait_list(ModelAction *act) { wait_list.push_back(act); }
/**
- * Remove one Thread from the waiting list
- * @return The Thread that was removed from the waiting list
+ * Remove one ModelAction from the waiting list
+ * @return The ModelAction that was removed from the waiting list
*/
- Thread * pop_wait_list() {
- Thread *ret = wait_list.front();
+ ModelAction * pop_wait_list() {
+ ModelAction *ret = wait_list.front();
wait_list.pop_back();
return ret;
}
thread_state state;
/**
- * A list of Threads waiting on this Thread. Particularly, this list is
- * used for thread joins, where another Thread waits for this Thread to
- * complete
+ * A list of ModelActions waiting on this Thread. Particularly, this
+ * list is used for thread joins, where another Thread waits for this
+ * Thread to complete
*/
- std::vector<Thread *> wait_list;
+ std::vector<ModelAction *> wait_list;
/**
* The value returned by the last action in this thread