From: Brian Norris <banorris@uci.edu>
Date: Wed, 14 Nov 2012 23:43:39 +0000 (-0800)
Subject: schedule: improve is_enabled() routines
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c633515be9def3f6fd74843974b36d923d7b44a4;p=cdsspec-compiler.git

schedule: improve is_enabled() routines

The comments don't clearly explain what is_enabled() might include
(i.e., SLEEP_SET, ENABLED, or DISABLED). Also, we need a direct accessor
keyed by thread_id_t, not just by class Thread.
---

diff --git a/schedule.cc b/schedule.cc
index 93379c2..26217d0 100644
--- a/schedule.cc
+++ b/schedule.cc
@@ -35,13 +35,29 @@ void Scheduler::set_enabled(Thread *t, enabled_type_t enabled_status) {
 
 /**
  * @brief Check if a Thread is currently enabled
+ *
+ * Check if a Thread is currently enabled. "Enabled" includes both
+ * THREAD_ENABLED and THREAD_SLEEP_SET.
  * @param t The Thread to check
  * @return True if the Thread is currently enabled
  */
 bool Scheduler::is_enabled(Thread *t) const
 {
-	int id = id_to_int(t->get_id());
-	return (id >= enabled_len) ? false : (enabled[id] != THREAD_DISABLED);
+	return is_enabled(t->get_id());
+}
+
+/**
+ * @brief Check if a Thread is currently enabled
+ *
+ * Check if a Thread is currently enabled. "Enabled" includes both
+ * THREAD_ENABLED and THREAD_SLEEP_SET.
+ * @param tid The ID of the Thread to check
+ * @return True if the Thread is currently enabled
+ */
+bool Scheduler::is_enabled(thread_id_t tid) const
+{
+	int i = id_to_int(tid);
+	return (i >= enabled_len) ? false : (enabled[i] != THREAD_DISABLED);
 }
 
 enabled_type_t Scheduler::get_enabled(Thread *t) {
diff --git a/schedule.h b/schedule.h
index 7267059..da91fdd 100644
--- a/schedule.h
+++ b/schedule.h
@@ -36,6 +36,7 @@ public:
 	enabled_type_t get_enabled(Thread *t);
 	void update_sleep_set(Node *n);
 	bool is_enabled(Thread *t) const;
+	bool is_enabled(thread_id_t tid) const;
 
 	SNAPSHOTALLOC
 private: