From 62dbff8dbca80ded5959e88ec9c177bef9108546 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 5 Feb 2013 13:44:32 -0800 Subject: [PATCH] cyclegraph: return 'added' status for addEdge() The ModelChecker would like to know if it's adding a new edge, or just and existing edge. If the edge is not new, then there are fewer resulting update checks needed. --- cyclegraph.cc | 12 +++++++++--- cyclegraph.h | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cyclegraph.cc b/cyclegraph.cc index 3bb5ab8..eaddc8e 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -168,13 +168,16 @@ bool CycleGraph::mergeNodes(CycleNode *w_node, CycleNode *p_node, * Adds an edge between two CycleNodes. * @param fromnode The edge comes from this CycleNode * @param tonode The edge points to this CycleNode + * @return True, if new edge(s) are added; otherwise false */ -void CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) +bool CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) { + bool added; + if (!hasCycles) hasCycles = checkReachable(tonode, fromnode); - if (fromnode->addEdge(tonode)) + if ((added = fromnode->addEdge(tonode))) rollbackvector.push_back(fromnode); /* @@ -186,9 +189,12 @@ void CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) if (!hasCycles) hasCycles = checkReachable(tonode, rmwnode); - if (rmwnode->addEdge(tonode)) + if (rmwnode->addEdge(tonode)) { rollbackvector.push_back(rmwnode); + added = true; + } } + return added; } /** diff --git a/cyclegraph.h b/cyclegraph.h index 83d3db2..749abf8 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -28,7 +28,7 @@ class CycleGraph { ~CycleGraph(); template - void addEdge(const T from, const U to); + bool addEdge(const T from, const U to); bool checkForCycles() const; void addRMWEdge(const ModelAction *from, const ModelAction *rmw); @@ -50,7 +50,7 @@ class CycleGraph { SNAPSHOTALLOC private: - void addNodeEdge(CycleNode *fromnode, CycleNode *tonode); + bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode); void putNode(const ModelAction *act, CycleNode *node); CycleNode * getNode(const ModelAction *act); CycleNode * getNode(const Promise *promise); @@ -141,9 +141,10 @@ class CycleNode { * * @param to The edge points to this object, of type T * @param from The edge comes from this object, of type U + * @return True, if new edge(s) are added; otherwise false */ template -void CycleGraph::addEdge(const T from, const U to) +bool CycleGraph::addEdge(const T from, const U to) { ASSERT(from); ASSERT(to); @@ -151,7 +152,7 @@ void CycleGraph::addEdge(const T from, const U to) CycleNode *fromnode = getNode(from); CycleNode *tonode = getNode(to); - addNodeEdge(fromnode, tonode); + return addNodeEdge(fromnode, tonode); } /** -- 2.34.1