#include "model.h"
/** @brief Node constructor */
-Node::Node(ModelAction *act, int nthreads)
+Node::Node(ModelAction *act, Node *par, int nthreads)
: action(act),
+ parent(par),
num_threads(nthreads),
explored_children(num_threads),
- backtrack(num_threads)
+ backtrack(num_threads),
+ numBacktracks(0),
+ may_read_from()
{
}
*/
bool Node::backtrack_empty()
{
- unsigned int i;
- for (i = 0; i < backtrack.size(); i++)
- if (backtrack[i] == true)
- return false;
- return true;
+ return numBacktracks == 0;
}
/**
if (backtrack[i])
return false;
backtrack[i] = true;
+ numBacktracks++;
return true;
}
if (i >= backtrack.size())
return THREAD_ID_T_NONE;
backtrack[i] = false;
+ numBacktracks--;
return int_to_id(i);
}
return id_to_int(t->get_id()) < num_threads;
}
+/**
+ * Add an action to the may_read_from set.
+ * @param act is the action to add
+ */
+void Node::add_read_from(ModelAction *act)
+{
+ may_read_from.insert(act);
+}
+
void Node::explore(thread_id_t tid)
{
int i = id_to_int(tid);
- backtrack[i] = false;
+ if (backtrack[i]) {
+ backtrack[i] = false;
+ numBacktracks--;
+ }
explored_children[i] = true;
}
/* Record action */
get_head()->explore_child(act);
- node_list.push_back(new Node(act, model->get_num_threads()));
+ node_list.push_back(new Node(act, get_head(), model->get_num_threads()));
total_nodes++;
iter++;
return NULL;