+#include "nodestack.h"
+
+/** Constructor */
+Scheduler::Scheduler() :
+ enabled(NULL),
+ enabled_len(0),
+ curr_thread_index(0),
+ current(NULL)
+{
+}
+
+void Scheduler::set_enabled(Thread *t, enabled_type_t enabled_status) {
+ int threadid=id_to_int(t->get_id());
+ if (threadid>=enabled_len) {
+ enabled_type_t *new_enabled = (enabled_type_t *)snapshot_malloc(sizeof(enabled_type_t) * (threadid + 1));
+ memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(enabled_type_t));
+ if (enabled != NULL) {
+ memcpy(new_enabled, enabled, enabled_len*sizeof(enabled_type_t));
+ snapshot_free(enabled);
+ }
+ enabled=new_enabled;
+ enabled_len=threadid+1;
+ }
+ enabled[threadid]=enabled_status;
+}
+
+/**
+ * @brief Check if a Thread is currently enabled
+ * @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);
+}
+
+enabled_type_t Scheduler::get_enabled(Thread *t) {
+ return enabled[id_to_int(t->get_id())];
+}
+
+void Scheduler::update_sleep_set(Node *n) {
+ enabled_type_t *enabled_array=n->get_enabled_array();
+ for(int i=0;i<enabled_len;i++) {
+ if (enabled_array[i]==THREAD_SLEEP_SET) {
+ enabled[i]=THREAD_SLEEP_SET;
+ }
+ }
+}