tree: revise arguments (use Thread, ModelAction)
authorBrian Norris <banorris@uci.edu>
Fri, 4 May 2012 06:27:46 +0000 (23:27 -0700)
committerBrian Norris <banorris@uci.edu>
Tue, 8 May 2012 17:35:33 +0000 (10:35 -0700)
Preparation for other changes to the TreeNode.

model.cc
tree.cc
tree.h

index aba3e8bc0c1783f87cad0c9b5b60b5ba9e3ae4c3..0084e74fcf69b989f8c2c91a8bdc747caa546494 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -43,7 +43,7 @@ ModelChecker::ModelChecker()
        this->exploring = NULL;
        this->nextThread = THREAD_ID_T_NONE;
 
-       rootNode = new TreeNode(NULL);
+       rootNode = new TreeNode();
        currentNode = rootNode;
        action_trace = new action_list_t();
 }
@@ -182,6 +182,7 @@ void ModelChecker::set_backtracking(ModelAction *act)
 {
        ModelAction *prev;
        TreeNode *node;
+       Thread *t = get_thread(act->get_tid());
 
        prev = get_last_conflict(act);
        if (prev == NULL)
@@ -190,14 +191,14 @@ void ModelChecker::set_backtracking(ModelAction *act)
        node = prev->get_node();
 
        /* Check if this has been explored already */
-       if (node->hasBeenExplored(act->get_tid()))
+       if (node->hasBeenExplored(t->get_id()))
                return;
        /* If this is a new backtracking point, mark the tree */
-       if (node->setBacktrack(act->get_tid()) != 0)
+       if (node->setBacktrack(t->get_id()) != 0)
                return;
 
        DEBUG("Setting backtrack: conflict = %d, instead tid = %d\n",
-                       prev->get_tid(), act->get_tid());
+                       prev->get_tid(), t->get_id());
        if (DBG_ENABLED()) {
                prev->print();
                act->print();
@@ -229,7 +230,7 @@ void ModelChecker::check_current_action(void)
        nextThread = advance_backtracking_state();
        next->set_node(currentNode);
        set_backtracking(next);
-       currentNode = currentNode->exploreChild(next->get_tid());
+       currentNode = currentNode->explore_child(next);
        this->action_trace->push_back(next);
 }
 
diff --git a/tree.cc b/tree.cc
index ce79f755eeea010897bc117f47deab11bb53786e..57e0c13f69902f071cb336d3a155a15db38f4c08 100644 (file)
--- a/tree.cc
+++ b/tree.cc
@@ -1,8 +1,9 @@
 #include "tree.h"
+#include "action.h"
 
 int TreeNode::totalNodes = 0;
 
-TreeNode::TreeNode(TreeNode *par)
+TreeNode::TreeNode(TreeNode *par, ModelAction *act)
 {
        TreeNode::totalNodes++;
        this->parent = par;
@@ -15,14 +16,15 @@ TreeNode::~TreeNode() {
                delete it->second;
 }
 
-TreeNode * TreeNode::exploreChild(thread_id_t id)
+TreeNode * TreeNode::explore_child(ModelAction *act)
 {
        TreeNode *n;
        std::set<int>::iterator it;
+       thread_id_t id = act->get_tid();
        int i = id_to_int(id);
 
        if (!hasBeenExplored(id)) {
-               n = new TreeNode(this);
+               n = new TreeNode(this, act);
                children[i] = n;
        } else {
                n = children[i];
diff --git a/tree.h b/tree.h
index 9fba203473122b66a2a2fcc4d0cfc2cd54ca6649..1752d3fe57cdd9535a32a2b18c1e9ddaedf28e30 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -5,6 +5,8 @@
 #include <map>
 #include "threads.h"
 
+class ModelAction;
+
 /*
  * An n-ary tree
  *
  */
 class TreeNode {
 public:
-       TreeNode(TreeNode *par);
+       TreeNode(TreeNode *par = NULL, ModelAction *act = NULL);
        ~TreeNode();
        bool hasBeenExplored(thread_id_t id) { return children.find(id_to_int(id)) != children.end(); }
-       TreeNode * exploreChild(thread_id_t id);
+       TreeNode * explore_child(ModelAction *act);
        thread_id_t getNextBacktrack();
 
        /* Return 1 if already in backtrack, 0 otherwise */