6 /** @brief Node constructor */
7 Node::Node(ModelAction *act, int nthreads)
10 explored_children(num_threads),
11 backtrack(num_threads),
16 /** @brief Node desctructor */
23 /** Prints debugging info for the ModelAction associated with this Node */
29 printf("******** empty action ********\n");
33 * Checks if the Thread associated with this thread ID has been explored from
35 * @param tid is the thread ID to check
36 * @return true if this thread choice has been explored already, false
39 bool Node::has_been_explored(thread_id_t tid)
41 int id = id_to_int(tid);
42 return explored_children[id];
46 * Checks if the backtracking set is empty.
47 * @return true if the backtracking set is empty
49 bool Node::backtrack_empty()
51 return numBacktracks == 0;
55 * Explore a child Node using a given ModelAction. This updates both the
56 * Node-internal and the ModelAction data to associate the ModelAction with
58 * @param act is the ModelAction to explore
60 void Node::explore_child(ModelAction *act)
63 explore(act->get_tid());
67 * Records a backtracking reference for a thread choice within this Node.
68 * Provides feedback as to whether this thread choice is already set for
70 * @return false if the thread was already set to be backtracked, true
73 bool Node::set_backtrack(thread_id_t id)
75 int i = id_to_int(id);
83 thread_id_t Node::get_next_backtrack()
85 /* TODO: find next backtrack */
87 for (i = 0; i < backtrack.size(); i++)
88 if (backtrack[i] == true)
90 if (i >= backtrack.size())
91 return THREAD_ID_T_NONE;
97 bool Node::is_enabled(Thread *t)
99 return id_to_int(t->get_id()) < num_threads;
102 void Node::explore(thread_id_t tid)
104 int i = id_to_int(tid);
106 backtrack[i] = false;
109 explored_children[i] = true;
112 static void clear_node_list(node_list_t *list, node_list_t::iterator start,
113 node_list_t::iterator end)
115 node_list_t::iterator it;
117 for (it = start; it != end; it++)
119 list->erase(start, end);
122 NodeStack::NodeStack()
125 node_list.push_back(new Node());
127 iter = node_list.begin();
130 NodeStack::~NodeStack()
132 clear_node_list(&node_list, node_list.begin(), node_list.end());
135 void NodeStack::print()
137 node_list_t::iterator it;
138 printf("............................................\n");
139 printf("NodeStack printing node_list:\n");
140 for (it = node_list.begin(); it != node_list.end(); it++) {
141 if (it == this->iter)
142 printf("vvv following action is the current iterator vvv\n");
145 printf("............................................\n");
148 ModelAction * NodeStack::explore_action(ModelAction *act)
152 ASSERT(!node_list.empty());
154 if (get_head()->has_been_explored(act->get_tid())) {
156 return (*iter)->get_action();
159 /* Diverging from previous execution; clear out remainder of list */
160 node_list_t::iterator it = iter;
162 clear_node_list(&node_list, it, node_list.end());
165 get_head()->explore_child(act);
166 node_list.push_back(new Node(act, model->get_num_threads()));
172 Node * NodeStack::get_head()
174 if (node_list.empty())
179 Node * NodeStack::get_next()
181 node_list_t::iterator it = iter;
182 if (node_list.empty()) {
187 if (it == node_list.end()) {
194 void NodeStack::reset_execution()
196 iter = node_list.begin();