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");
50 * Checks if the Thread associated with this thread ID has been explored from
52 * @param tid is the thread ID to check
53 * @return true if this thread choice has been explored already, false
56 bool Node::has_been_explored(thread_id_t tid)
58 int id = id_to_int(tid);
59 return explored_children[id];
63 * Checks if the backtracking set is empty.
64 * @return true if the backtracking set is empty
66 bool Node::backtrack_empty()
68 return numBacktracks == 0;
72 * Mark the appropriate backtracking infromation for exploring a thread choice.
73 * @param act The ModelAction to explore
75 void Node::explore_child(ModelAction *act)
77 explore(act->get_tid());
81 * Records a backtracking reference for a thread choice within this Node.
82 * Provides feedback as to whether this thread choice is already set for
84 * @return false if the thread was already set to be backtracked, true
87 bool Node::set_backtrack(thread_id_t id)
89 int i = id_to_int(id);
97 thread_id_t Node::get_next_backtrack()
99 /* TODO: find next backtrack */
101 for (i = 0; i < backtrack.size(); i++)
102 if (backtrack[i] == true)
104 if (i >= backtrack.size())
105 return THREAD_ID_T_NONE;
106 backtrack[i] = false;
111 bool Node::is_enabled(Thread *t)
113 return id_to_int(t->get_id()) < num_threads;
117 * Add an action to the may_read_from set.
118 * @param act is the action to add
120 void Node::add_read_from(ModelAction *act)
122 may_read_from.insert(act);
125 void Node::explore(thread_id_t tid)
127 int i = id_to_int(tid);
129 backtrack[i] = false;
132 explored_children[i] = true;
135 static void clear_node_list(node_list_t *list, node_list_t::iterator start,
136 node_list_t::iterator end)
138 node_list_t::iterator it;
140 for (it = start; it != end; it++)
142 list->erase(start, end);
145 NodeStack::NodeStack()
148 node_list.push_back(new Node());
150 iter = node_list.begin();
153 NodeStack::~NodeStack()
155 clear_node_list(&node_list, node_list.begin(), node_list.end());
158 void NodeStack::print()
160 node_list_t::iterator it;
161 printf("............................................\n");
162 printf("NodeStack printing node_list:\n");
163 for (it = node_list.begin(); it != node_list.end(); it++) {
164 if (it == this->iter)
165 printf("vvv following action is the current iterator vvv\n");
168 printf("............................................\n");
171 ModelAction * NodeStack::explore_action(ModelAction *act)
175 ASSERT(!node_list.empty());
177 if (get_head()->has_been_explored(act->get_tid())) {
179 return (*iter)->get_action();
182 /* Diverging from previous execution; clear out remainder of list */
183 node_list_t::iterator it = iter;
185 clear_node_list(&node_list, it, node_list.end());
188 get_head()->explore_child(act);
189 node_list.push_back(new Node(act, get_head(), model->get_num_threads()));
195 Node * NodeStack::get_head()
197 if (node_list.empty())
202 Node * NodeStack::get_next()
204 node_list_t::iterator it = iter;
205 if (node_list.empty()) {
210 if (it == node_list.end()) {
217 void NodeStack::reset_execution()
219 iter = node_list.begin();