X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=cyclegraph.cc;h=26ea215d434921f2b27fd69e07ef18d1e6029f54;hb=d62cd6e5bbba2975923540d99bae0587fe03b791;hp=20623347213d0958bfdff79d142595420461b015;hpb=7524803854c2de38c0311fe5037e3c17105ccfaa;p=model-checker.git diff --git a/cyclegraph.cc b/cyclegraph.cc index 2062334..26ea215 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -8,7 +8,7 @@ /** Initializes a CycleGraph object. */ CycleGraph::CycleGraph() : discovered(new HashTable(16)), - queue(new model_vector< const CycleNode * >()), + queue(new ModelVector()), hasCycles(false), oldCycles(false) { @@ -198,29 +198,33 @@ bool CycleGraph::mergeNodes(CycleNode *w_node, CycleNode *p_node) */ bool CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) { - bool added; - - if ((added = fromnode->addEdge(tonode))) { + if (fromnode->addEdge(tonode)) { rollbackvector.push_back(fromnode); if (!hasCycles) hasCycles = checkReachable(tonode, fromnode); - } + } else + return false; /* No new edge */ /* - * If the fromnode has a rmwnode that is not the tonode, we should add - * an edge between its rmwnode and the tonode + * If the fromnode has a rmwnode that is not the tonode, we should + * follow its RMW chain to add an edge at the end, unless we encounter + * tonode along the way */ CycleNode *rmwnode = fromnode->getRMW(); - if (rmwnode && rmwnode != tonode) { - if (rmwnode->addEdge(tonode)) { - if (!hasCycles) - hasCycles = checkReachable(tonode, rmwnode); + if (rmwnode) { + while (rmwnode != tonode && rmwnode->getRMW()) + rmwnode = rmwnode->getRMW(); - rollbackvector.push_back(rmwnode); - added = true; + if (rmwnode != tonode) { + if (rmwnode->addEdge(tonode)) { + if (!hasCycles) + hasCycles = checkReachable(tonode, rmwnode); + + rollbackvector.push_back(rmwnode); + } } } - return added; + return true; } /** @@ -244,6 +248,9 @@ void CycleGraph::addRMWEdge(const T *from, const ModelAction *rmw) CycleNode *fromnode = getNode(from); CycleNode *rmwnode = getNode(rmw); + /* We assume that this RMW has no RMW reading from it yet */ + ASSERT(!rmwnode->getRMW()); + /* Two RMW actions cannot read from the same write. */ if (fromnode->setRMW(rmwnode)) hasCycles = true; @@ -554,7 +561,7 @@ unsigned int CycleNode::getNumBackEdges() const * @return True if the element was found; false otherwise */ template -static bool vector_remove_node(std::vector >& v, const T n) +static bool vector_remove_node(SnapVector& v, const T n) { for (unsigned int i = 0; i < v.size(); i++) { if (v[i] == n) {