From 3e6579acd2456b1a7e0fc0aaa7e2e9b5bdb78a27 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 11 Sep 2012 19:38:50 -0700 Subject: [PATCH] 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. --- schedule.cc | 11 +++++++++++ schedule.h | 1 + 2 files changed, 12 insertions(+) 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; -- 2.34.1