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;
18 rootNode = new TreeNode(NULL);
19 currentNode = rootNode;
22 ModelChecker::~ModelChecker()
24 delete this->scheduler;
28 void ModelChecker::assign_id(Thread *t)
30 t->set_id(++used_thread_id);
33 void ModelChecker::add_system_thread(Thread *t)
35 this->system_thread = t;
38 void ModelChecker::check_current_action(void)
40 ModelAction *next = this->current_action;
43 DEBUG("trying to push NULL action...\n");
46 next->set_node(currentNode);
47 set_backtracking(next);
48 currentNode = currentNode->exploreChild(next->get_tid());
49 this->action_trace.push_back(next);
52 void ModelChecker::print_trace(void)
54 std::list<class ModelAction *>::iterator it;
56 for (it = action_trace.begin(); it != action_trace.end(); it++) {
62 int ModelChecker::add_thread(Thread *t)
64 thread_map[t->get_id()] = t;
68 int ModelChecker::switch_to_master(ModelAction *act)
73 old = thread_current();
74 set_current_action(act);
75 old->set_state(THREAD_READY);
77 return old->swap(next);
80 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
82 Thread *t = thread_current();
83 ModelAction *act = this;
88 act->tid = t->get_id();
92 void ModelAction::print(void)
97 type_str = "thread create";
100 type_str = "thread yield";
103 type_str = "thread join";
106 type_str = "atomic read";
109 type_str = "atomic write";
112 type_str = "unknown type";
115 printf("Thread: %d\tAction: %s\tMO: %d\tLoc: %#014zx\tValue: %d\n", tid, type_str, order, (size_t)location, value);