6 /** @brief Node constructor */
7 Node::Node(ModelAction *act, int nthreads)
10 explored_children(num_threads),
11 backtrack(num_threads)
15 /** @brief Node desctructor */
22 /** Prints debugging info for the ModelAction associated with this Node */
28 printf("******** empty action ********\n");
32 * Checks if the Thread associated with this thread ID has been explored from
34 * @param tid is the thread ID to check
35 * @return true if this thread choice has been explored already, false
38 bool Node::has_been_explored(thread_id_t tid)
40 int id = id_to_int(tid);
41 return explored_children[id];
45 * Checks if the backtracking set is empty.
46 * @return true if the backtracking set is empty
48 bool Node::backtrack_empty()
51 for (i = 0; i < backtrack.size(); i++)
52 if (backtrack[i] == true)
58 * Explore a child Node using a given ModelAction. This updates both the
59 * Node-internal and the ModelAction data to associate the ModelAction with
61 * @param act is the ModelAction to explore
63 void Node::explore_child(ModelAction *act)
66 explore(act->get_tid());
70 * Records a backtracking reference for a thread choice within this Node.
71 * Provides feedback as to whether this thread choice is already set for
73 * @return false if the thread was already set to be backtracked, true
76 bool Node::set_backtrack(thread_id_t id)
78 int i = id_to_int(id);
85 thread_id_t Node::get_next_backtrack()
87 /* TODO: find next backtrack */
89 for (i = 0; i < backtrack.size(); i++)
90 if (backtrack[i] == true)
92 if (i >= backtrack.size())
93 return THREAD_ID_T_NONE;
98 bool Node::is_enabled(Thread *t)
100 return id_to_int(t->get_id()) < num_threads;
103 void Node::explore(thread_id_t tid)
105 int i = id_to_int(tid);
106 backtrack[i] = false;
107 explored_children[i] = true;
110 static void clear_node_list(node_list_t *list, node_list_t::iterator start,
111 node_list_t::iterator end)
113 node_list_t::iterator it;
115 for (it = start; it != end; it++)
117 list->erase(start, end);
120 NodeStack::NodeStack()
123 node_list.push_back(new Node());
125 iter = node_list.begin();
128 NodeStack::~NodeStack()
130 clear_node_list(&node_list, node_list.begin(), node_list.end());
133 void NodeStack::print()
135 node_list_t::iterator it;
136 printf("............................................\n");
137 printf("NodeStack printing node_list:\n");
138 for (it = node_list.begin(); it != node_list.end(); it++) {
139 if (it == this->iter)
140 printf("vvv following action is the current iterator vvv\n");
143 printf("............................................\n");
146 ModelAction * NodeStack::explore_action(ModelAction *act)
150 ASSERT(!node_list.empty());
152 if (get_head()->has_been_explored(act->get_tid())) {
153 /* Discard duplicate ModelAction */
156 } else { /* Diverging from previous execution */
157 /* Clear out remainder of list */
158 node_list_t::iterator it = iter;
160 clear_node_list(&node_list, it, node_list.end());
163 get_head()->explore_child(act);
164 node_list.push_back(new Node(act, model->get_num_threads()));
168 return (*iter)->get_action();
171 Node * NodeStack::get_head()
173 if (node_list.empty())
178 Node * NodeStack::get_next()
180 node_list_t::iterator it = iter;
181 if (node_list.empty()) {
186 if (it == node_list.end()) {
193 void NodeStack::reset_execution()
195 iter = node_list.begin();