fixup more id vs. thread_id_t
[c11tester.git] / schedule.cc
index 8883d2a9b82cccc78a47b62a14d05e0e64ee52a5..88200a81cc650617044b4b0449477fbed1afb4e9 100644 (file)
@@ -1,3 +1,6 @@
+#include <string.h>
+#include <stdlib.h>
+
 #include "threads.h"
 #include "schedule.h"
 #include "common.h"
@@ -15,11 +18,11 @@ 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));
+               bool *new_enabled = (bool *)snapshot_malloc(sizeof(bool) * (threadid + 1));
                memset(&new_enabled[enabled_len], 0, (threadid+1-enabled_len)*sizeof(bool));
                if (is_enabled != NULL) {
                        memcpy(new_enabled, is_enabled, enabled_len*sizeof(bool));
-                       free(is_enabled);
+                       snapshot_free(is_enabled);
                }
                is_enabled=new_enabled;
                enabled_len=threadid+1;
@@ -33,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);
 }
 
@@ -70,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.
@@ -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");
 }