towards freeing actions
[c11tester.git] / cyclegraph.cc
index f8d3b85297b981b98ceff9930b726f854d9a6f42..849c00d9cbc586a0a8ff2b2d3edf274432e0ff95 100644 (file)
@@ -131,7 +131,7 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw)
                if (tonode != rmwnode) {
                        rmwnode->addEdge(tonode);
                }
-               tonode->refcount--;
+               tonode->removeInEdge(fromnode);
        }
        fromnode->edges.clear();
 
@@ -291,6 +291,15 @@ bool CycleGraph::checkReachable(const ModelAction *from, const ModelAction *to)
        return checkReachable(fromnode, tonode);
 }
 
+void CycleGraph::freeAction(const ModelAction * act) {
+       CycleNode *cn = actionToNode.remove(act);
+       for(unsigned int i=0;i<cn->edges.size();i++) {
+               CycleNode *dst = cn->edges[i];
+               dst->removeInEdge(cn);
+       }
+       delete cn;
+}
+
 /**
  * @brief Constructor for a CycleNode
  * @param act The ModelAction for this node
@@ -298,11 +307,24 @@ bool CycleGraph::checkReachable(const ModelAction *from, const ModelAction *to)
 CycleNode::CycleNode(const ModelAction *act) :
        action(act),
        hasRMW(NULL),
-       cv(new ClockVector(NULL, act)),
-       refcount(0)
+       cv(new ClockVector(NULL, act))
 {
 }
 
+CycleNode::~CycleNode() {
+       delete cv;
+}
+
+void CycleNode::removeInEdge(CycleNode *src) {
+       for(unsigned int i=0;i < edges.size();i++) {
+               if (edges[i] == src) {
+                       edges[i] = edges[edges.size()-1];
+                       edges.pop_back();
+                       break;
+               }
+       }
+}
+
 /**
  * @param i The index of the edge to return
  * @returns The CycleNode edge indexed by i
@@ -329,7 +351,7 @@ void CycleNode::addEdge(CycleNode *node)
                if (edges[i] == node)
                        return;
        edges.push_back(node);
-       node->refcount++;
+       node->inedges.push_back(this);
 }
 
 /** @returns the RMW CycleNode that reads from the current CycleNode */