X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=model.cc;h=88d5ce32e21195d7106c291220d4eb2af7bb80a0;hb=f646d6a9d7c201e54a3f7eb1f026064d4136cf2e;hp=858b9198bccc2fea775d3870970c9f4a0e19ef7e;hpb=bb44088ca96e320475d4ebd11f8868ac4b452fbb;p=model-checker.git diff --git a/model.cc b/model.cc index 858b919..88d5ce3 100644 --- a/model.cc +++ b/model.cc @@ -1,7 +1,7 @@ +#include + #include "model.h" #include "schedule.h" -#include -#include ModelChecker *model; @@ -9,17 +9,15 @@ ModelChecker::ModelChecker() { /* First thread created (system_thread) will have id 1 */ this->used_thread_id = 0; + /* Initialize default scheduler */ + this->scheduler = new DefaultScheduler(); - scheduler_init(this); + this->current_action = NULL; } ModelChecker::~ModelChecker() { - struct scheduler *sched = model->scheduler; - - if (sched->exit) - sched->exit(); - free(sched); + delete this->scheduler; } void ModelChecker::assign_id(struct thread *t) @@ -29,5 +27,43 @@ void ModelChecker::assign_id(struct thread *t) void ModelChecker::add_system_thread(struct thread *t) { - model->system_thread = t; + this->system_thread = t; +} + +ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value) +{ + struct thread *t = thread_current(); + ModelAction *act = this; + + act->type = type; + act->order = order; + act->location = loc; + act->tid = t->id; + act->value = value; +} + +void ModelAction::print(void) +{ + const char *type_str; + switch (this->type) { + case THREAD_CREATE: + type_str = "thread create"; + break; + case THREAD_YIELD: + type_str = "thread yield"; + break; + case THREAD_JOIN: + type_str = "thread join"; + break; + case ATOMIC_READ: + type_str = "atomic read"; + break; + case ATOMIC_WRITE: + type_str = "atomic write"; + break; + default: + type_str = "unknown type"; + } + + printf("Thread: %d\tAction: %s\tMO: %d\tLoc: %#014zx\tValue: %d\n", tid, type_str, order, (size_t)location, value); }