schedule: add sleep() function
authorBrian Norris <banorris@uci.edu>
Wed, 12 Sep 2012 02:38:50 +0000 (19:38 -0700)
committerBrian Norris <banorris@uci.edu>
Wed, 12 Sep 2012 02:38:50 +0000 (19:38 -0700)
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
schedule.h

index be4a92f..9063fdb 100644 (file)
@@ -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
index 664b2d2..7875e0b 100644 (file)
@@ -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;