fixup more id vs. thread_id_t
[c11tester.git] / schedule.cc
index 5c93381b99763344d3fce9548a39955c041c6d79..88200a81cc650617044b4b0449477fbed1afb4e9 100644 (file)
@@ -1,3 +1,6 @@
+#include <string.h>
+#include <stdlib.h>
+
 #include "threads.h"
 #include "schedule.h"
 #include "common.h"
@@ -15,10 +18,12 @@ Scheduler::Scheduler() :
 void Scheduler::set_enabled(Thread *t, bool enabled_status) {
        int threadid=id_to_int(t->get_id());
        if (threadid>=enabled_len) {
-               bool * new_enabled=(bool *)malloc(sizeof(bool)*(threadid+1));
-               memcpy(new_enabled, is_enabled, enabled_len*sizeof(bool));
+               bool *new_enabled = (bool *)snapshot_malloc(sizeof(bool) * (threadid + 1));
                memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(bool));
-               free(is_enabled);
+               if (is_enabled != NULL) {
+                       memcpy(new_enabled, is_enabled, enabled_len*sizeof(bool));
+                       snapshot_free(is_enabled);
+               }
                is_enabled=new_enabled;
                enabled_len=threadid+1;
        }
@@ -31,7 +36,7 @@ void Scheduler::set_enabled(Thread *t, bool enabled_status) {
  */
 void Scheduler::add_thread(Thread *t)
 {
-       DEBUG("thread %d\n", t->get_id());
+       DEBUG("thread %d\n", id_to_int(t->get_id()));
        set_enabled(t, true);
 }
 
@@ -68,8 +73,8 @@ void Scheduler::wake(Thread *t)
 }
 
 /**
- * Remove one Thread from the scheduler. This implementation defaults to FIFO,
- * if a thread is not already provided.
+ * Select a Thread. This implementation defaults to round-robin, if a
+ * thread is not already provided.
  *
  * @param t Thread to run, if chosen by an external entity (e.g.,
  * ModelChecker). May be NULL to indicate no external choice.
@@ -77,7 +82,6 @@ void Scheduler::wake(Thread *t)
  */
 Thread * Scheduler::next_thread(Thread *t)
 {
-       printf("%p\n",t);
        if ( t == NULL ) {
                int old_curr_thread = curr_thread_index;
                while(true) {
@@ -94,7 +98,6 @@ Thread * Scheduler::next_thread(Thread *t)
        } else {
                curr_thread_index = id_to_int(t->get_id());
        }
-       printf("index=%u enabled=%u\n", curr_thread_index, is_enabled[curr_thread_index]);
 
        current = t;
        print();
@@ -116,7 +119,7 @@ Thread * Scheduler::get_current_thread() const
 void Scheduler::print() const
 {
        if (current)
-               DEBUG("Current thread: %d\n", current->get_id());
+               DEBUG("Current thread: %d\n", id_to_int(current->get_id()));
        else
                DEBUG("No current thread\n");
 }