9 ModelChecker::ModelChecker()
11 /* First thread created (system_thread) will have id 1 */
12 this->used_thread_id = 0;
13 /* Initialize default scheduler */
14 this->scheduler = new Scheduler();
16 this->current_action = NULL;
19 ModelChecker::~ModelChecker()
21 delete this->scheduler;
24 void ModelChecker::assign_id(Thread *t)
26 t->set_id(++used_thread_id);
29 void ModelChecker::add_system_thread(Thread *t)
31 this->system_thread = t;
34 void ModelChecker::check_current_action(void)
36 if (this->current_action)
37 this->action_trace.push_back(this->current_action);
39 DEBUG("trying to push NULL action...\n");
42 void ModelChecker::print_trace(void)
44 std::list<class ModelAction *>::iterator it;
46 for (it = action_trace.begin(); it != action_trace.end(); it++) {
52 int ModelChecker::add_thread(Thread *t)
54 thread_map[t->get_id()] = t;
58 int ModelChecker::switch_to_master(ModelAction *act)
63 old = thread_current();
64 set_current_action(act);
65 old->set_state(THREAD_READY);
67 return old->swap(next);
70 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
72 Thread *t = thread_current();
73 ModelAction *act = this;
78 act->tid = t->get_id();
82 void ModelAction::print(void)
87 type_str = "thread create";
90 type_str = "thread yield";
93 type_str = "thread join";
96 type_str = "atomic read";
99 type_str = "atomic write";
102 type_str = "unknown type";
105 printf("Thread: %d\tAction: %s\tMO: %d\tLoc: %#014zx\tValue: %d\n", tid, type_str, order, (size_t)location, value);