merge massive speedup with release sequence support...
[model-checker.git] / schedule.cc
index dd35237..ea1d582 100644 (file)
@@ -5,6 +5,7 @@
 #include "schedule.h"
 #include "common.h"
 #include "model.h"
+#include "nodestack.h"
 
 /** Constructor */
 Scheduler::Scheduler() :
@@ -38,7 +39,40 @@ void Scheduler::set_enabled(Thread *t, enabled_type_t enabled_status) {
 bool Scheduler::is_enabled(Thread *t) const
 {
        int id = id_to_int(t->get_id());
-       return (id >= enabled_len) ? false : (enabled[id] == THREAD_ENABLED);
+       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;
+               }
+       }
+}
+
+/**
+ * Add a Thread to the sleep set.
+ * @param t The Thread to add
+ */
+void Scheduler::add_sleep(Thread *t)
+{
+       DEBUG("thread %d\n", id_to_int(t->get_id()));
+       set_enabled(t, THREAD_SLEEP_SET);
+}
+
+/**
+ * Remove a Thread from the sleep set.
+ * @param t The Thread to remove
+ */
+void Scheduler::remove_sleep(Thread *t)
+{
+       DEBUG("thread %d\n", id_to_int(t->get_id()));
+       set_enabled(t, THREAD_ENABLED);
 }
 
 /**
@@ -99,7 +133,7 @@ Thread * Scheduler::next_thread(Thread *t)
                int old_curr_thread = curr_thread_index;
                while(true) {
                        curr_thread_index = (curr_thread_index+1) % enabled_len;
-                       if (enabled[curr_thread_index]) {
+                       if (enabled[curr_thread_index]==THREAD_ENABLED) {
                                t = model->get_thread(int_to_id(curr_thread_index));
                                break;
                        }