From c633515be9def3f6fd74843974b36d923d7b44a4 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 14 Nov 2012 15:43:39 -0800 Subject: [PATCH] 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. --- schedule.cc | 20 ++++++++++++++++++-- schedule.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) 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: -- 2.34.1