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::set_backtracking(ModelAction *act)
43 prev = get_last_conflict(act);
47 node = prev->get_node();
49 /* Check if this has been explored already */
50 if (node->hasBeenExplored(act->get_tid()))
52 /* If this is a new backtracking point, mark the tree */
53 if (node->setBacktrack(act->get_tid()) != 0)
56 printf("Setting backtrack: conflict = %d, instead tid = %d\n",
57 prev->get_tid(), act->get_tid());
62 //Backtrack *back = new Backtrack(prev, actionList);
63 //backtrackList->Append(back);
66 void ModelChecker::check_current_action(void)
68 ModelAction *next = this->current_action;
71 DEBUG("trying to push NULL action...\n");
74 next->set_node(currentNode);
75 set_backtracking(next);
76 currentNode = currentNode->exploreChild(next->get_tid());
77 this->action_trace.push_back(next);
80 void ModelChecker::print_trace(void)
82 std::list<class ModelAction *>::iterator it;
84 for (it = action_trace.begin(); it != action_trace.end(); it++) {
90 int ModelChecker::add_thread(Thread *t)
92 thread_map[t->get_id()] = t;
96 int ModelChecker::switch_to_master(ModelAction *act)
101 old = thread_current();
102 set_current_action(act);
103 old->set_state(THREAD_READY);
104 next = system_thread;
105 return old->swap(next);
108 ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value)
110 Thread *t = thread_current();
111 ModelAction *act = this;
116 act->tid = t->get_id();
120 void ModelAction::print(void)
122 const char *type_str;
123 switch (this->type) {
125 type_str = "thread create";
128 type_str = "thread yield";
131 type_str = "thread join";
134 type_str = "atomic read";
137 type_str = "atomic write";
140 type_str = "unknown type";
143 printf("Thread: %d\tAction: %s\tMO: %d\tLoc: %#014zx\tValue: %d\n", tid, type_str, order, (size_t)location, value);