7 * @brief Node constructor
9 * Constructs a single Node for use in a NodeStack. Each Node is associated
10 * with exactly one ModelAction (exception: the first Node should be created
11 * as an empty stub, to represent the first thread "choice") and up to one
14 * @param act The ModelAction to associate with this Node. May be NULL.
15 * @param par The parent Node in the NodeStack. May be NULL if there is no
17 * @param nthreads The number of threads which exist at this point in the
20 Node::Node(ModelAction *act, Node *par, int nthreads)
23 num_threads(nthreads),
24 explored_children(num_threads),
25 backtrack(num_threads),
33 /** @brief Node desctructor */
40 /** Prints debugging info for the ModelAction associated with this Node */
46 printf("******** empty action ********\n");
49 /** @brief Prints info about may_read_from set */
50 void Node::print_may_read_from()
52 readfrom_set_t::iterator it;
53 for (it = may_read_from.begin(); it != may_read_from.end(); it++)
58 * Checks if the Thread associated with this thread ID has been explored from
60 * @param tid is the thread ID to check
61 * @return true if this thread choice has been explored already, false
64 bool Node::has_been_explored(thread_id_t tid)
66 int id = id_to_int(tid);
67 return explored_children[id];
71 * Checks if the backtracking set is empty.
72 * @return true if the backtracking set is empty
74 bool Node::backtrack_empty()
76 return numBacktracks == 0;
80 * Mark the appropriate backtracking infromation for exploring a thread choice.
81 * @param act The ModelAction to explore
83 void Node::explore_child(ModelAction *act)
85 explore(act->get_tid());
89 * Records a backtracking reference for a thread choice within this Node.
90 * Provides feedback as to whether this thread choice is already set for
92 * @return false if the thread was already set to be backtracked, true
95 bool Node::set_backtrack(thread_id_t id)
97 int i = id_to_int(id);
105 thread_id_t Node::get_next_backtrack()
107 /* TODO: find next backtrack */
109 for (i = 0; i < backtrack.size(); i++)
110 if (backtrack[i] == true)
112 if (i >= backtrack.size())
113 return THREAD_ID_T_NONE;
114 backtrack[i] = false;
119 bool Node::is_enabled(Thread *t)
121 return id_to_int(t->get_id()) < num_threads;
125 * Add an action to the may_read_from set.
126 * @param act is the action to add
128 void Node::add_read_from(const ModelAction *act)
130 may_read_from.push_back(act);
133 void Node::explore(thread_id_t tid)
135 int i = id_to_int(tid);
137 backtrack[i] = false;
140 explored_children[i] = true;
143 static void clear_node_list(node_list_t *list, node_list_t::iterator start,
144 node_list_t::iterator end)
146 node_list_t::iterator it;
148 for (it = start; it != end; it++)
150 list->erase(start, end);
153 NodeStack::NodeStack()
156 node_list.push_back(new Node());
158 iter = node_list.begin();
161 NodeStack::~NodeStack()
163 clear_node_list(&node_list, node_list.begin(), node_list.end());
166 void NodeStack::print()
168 node_list_t::iterator it;
169 printf("............................................\n");
170 printf("NodeStack printing node_list:\n");
171 for (it = node_list.begin(); it != node_list.end(); it++) {
172 if (it == this->iter)
173 printf("vvv following action is the current iterator vvv\n");
176 printf("............................................\n");
179 ModelAction * NodeStack::explore_action(ModelAction *act)
183 ASSERT(!node_list.empty());
185 if (get_head()->has_been_explored(act->get_tid())) {
187 return (*iter)->get_action();
190 /* Diverging from previous execution; clear out remainder of list */
191 node_list_t::iterator it = iter;
193 clear_node_list(&node_list, it, node_list.end());
196 get_head()->explore_child(act);
197 node_list.push_back(new Node(act, get_head(), model->get_num_threads()));
203 Node * NodeStack::get_head()
205 if (node_list.empty())
210 Node * NodeStack::get_next()
212 node_list_t::iterator it = iter;
213 if (node_list.empty()) {
218 if (it == node_list.end()) {
225 void NodeStack::reset_execution()
227 iter = node_list.begin();