X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=cyclegraph.cc;h=e96549ff1fddcace369f57102572edf2c6bf9c32;hb=fa36db2da01d7da10e0cd375fda3c2db4ce3a05b;hp=f8cbdda81054a3992aa0f507c1b1bb8499887c5e;hpb=438b20cfc07029629c03b4f219c190cbdb5b9d1b;p=model-checker.git diff --git a/cyclegraph.cc b/cyclegraph.cc index f8cbdda..e96549f 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -8,6 +8,7 @@ /** Initializes a CycleGraph object. */ CycleGraph::CycleGraph() : discovered(new HashTable(16)), + queue(new std::vector< const CycleNode *, ModelAlloc >()), hasCycles(false), oldCycles(false) { @@ -16,6 +17,7 @@ CycleGraph::CycleGraph() : /** CycleGraph destructor */ CycleGraph::~CycleGraph() { + delete queue; delete discovered; } @@ -198,11 +200,11 @@ bool CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) { bool added; - if (!hasCycles) - hasCycles = checkReachable(tonode, fromnode); - - if ((added = fromnode->addEdge(tonode))) + if ((added = fromnode->addEdge(tonode))) { rollbackvector.push_back(fromnode); + if (!hasCycles) + hasCycles = checkReachable(tonode, fromnode); + } /* * If the fromnode has a rmwnode that is not the tonode, we should add @@ -210,10 +212,10 @@ bool CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) */ CycleNode *rmwnode = fromnode->getRMW(); if (rmwnode && rmwnode != tonode) { - if (!hasCycles) - hasCycles = checkReachable(tonode, rmwnode); - if (rmwnode->addEdge(tonode)) { + if (!hasCycles) + hasCycles = checkReachable(tonode, rmwnode); + rollbackvector.push_back(rmwnode); added = true; } @@ -386,22 +388,20 @@ void CycleGraph::dumpGraphToFile(const char *filename) const */ bool CycleGraph::checkReachable(const CycleNode *from, const CycleNode *to) const { - std::vector< const CycleNode *, ModelAlloc > queue; discovered->reset(); - - queue.push_back(from); + queue->clear(); + queue->push_back(from); discovered->put(from, from); - while (!queue.empty()) { - const CycleNode *node = queue.back(); - queue.pop_back(); + while (!queue->empty()) { + const CycleNode *node = queue->back(); + queue->pop_back(); if (node == to) return true; - for (unsigned int i = 0; i < node->getNumEdges(); i++) { CycleNode *next = node->getEdge(i); if (!discovered->contains(next)) { discovered->put(next, next); - queue.push_back(next); + queue->push_back(next); } } } @@ -425,26 +425,28 @@ bool CycleGraph::checkReachable(const T *from, const U *to) const return checkReachable(fromnode, tonode); } -/* Instantiate three forms of CycleGraph::checkReachable */ +/* Instantiate four forms of CycleGraph::checkReachable */ template bool CycleGraph::checkReachable(const ModelAction *from, const ModelAction *to) const; template bool CycleGraph::checkReachable(const ModelAction *from, const Promise *to) const; template bool CycleGraph::checkReachable(const Promise *from, const ModelAction *to) const; +template bool CycleGraph::checkReachable(const Promise *from, + const Promise *to) const; /** @return True, if the promise has failed; false otherwise */ bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) const { - std::vector< CycleNode *, ModelAlloc > queue; discovered->reset(); + queue->clear(); CycleNode *from = actionToNode.get(fromact); - queue.push_back(from); + queue->push_back(from); discovered->put(from, from); - while (!queue.empty()) { - CycleNode *node = queue.back(); - queue.pop_back(); + while (!queue->empty()) { + const CycleNode *node = queue->back(); + queue->pop_back(); if (node->getPromise() == promise) return true; @@ -456,7 +458,7 @@ bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) cons CycleNode *next = node->getEdge(i); if (!discovered->contains(next)) { discovered->put(next, next); - queue.push_back(next); + queue->push_back(next); } } }