From: Brian Norris Date: Wed, 12 Sep 2012 02:38:50 +0000 (-0700) Subject: schedule: add sleep() function X-Git-Tag: pldi2013~221 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=3e6579acd2456b1a7e0fc0aaa7e2e9b5bdb78a27 schedule: add sleep() function The wait() and wake() functions are not very complementary. I will be removing wait() in favor of a simpler sleep() function, which is introduced here. --- diff --git a/schedule.cc b/schedule.cc index be4a92f..9063fdb 100644 --- a/schedule.cc +++ b/schedule.cc @@ -45,6 +45,17 @@ void Scheduler::wait(Thread *wait, Thread *join) wait->set_state(THREAD_BLOCKED); } +/** + * Prevent a Thread from being scheduled. The sleeping Thread should be + * re-awoken via Scheduler::wake. + * @param thread The Thread that should sleep + */ +void Scheduler::sleep(Thread *t) +{ + remove_thread(t); + t->set_state(THREAD_BLOCKED); +} + /** * Wake a Thread up that was previously waiting (see Scheduler::wait) * @param t The Thread to wake up diff --git a/schedule.h b/schedule.h index 664b2d2..7875e0b 100644 --- a/schedule.h +++ b/schedule.h @@ -19,6 +19,7 @@ public: 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); Thread * get_current_thread() const;