X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=cyclegraph.cc;h=c0e8e2af006c5f6f0e0829571c1dc774fd79f391;hb=84e24d516d4e9dbd30f1fff7e9a185d1540d20eb;hp=dad8b7acb6975b0caccc1887394788b9f9dfff04;hpb=dd0190cef49ef760f8d86a6e92dd6eeb07197854;p=model-checker.git diff --git a/cyclegraph.cc b/cyclegraph.cc index dad8b7a..c0e8e2a 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -6,8 +6,11 @@ CycleGraph::CycleGraph() { hasCycles=false; } +CycleGraph::~CycleGraph() { +} + /** Returns the CycleNode for a given ModelAction. */ -CycleNode * CycleGraph::getNode(ModelAction * action) { +CycleNode * CycleGraph::getNode(const ModelAction * action) { CycleNode *node=actionToNode.get(action); if (node==NULL) { node=new CycleNode(action); @@ -17,16 +20,57 @@ CycleNode * CycleGraph::getNode(ModelAction * action) { } /** Adds an edge between two ModelActions. */ -void CycleGraph::addEdge(ModelAction *from, ModelAction *to) { + +//the event to happens after the event from + +void CycleGraph::addEdge(const ModelAction *to, const ModelAction *from) { CycleNode *fromnode=getNode(from); CycleNode *tonode=getNode(to); + if (!hasCycles) { // Check for Cycles - hasCycles=checkReachable(fromnode, tonode); + hasCycles=checkReachable(tonode, fromnode); } fromnode->addEdge(tonode); + + CycleNode * rmwnode=fromnode->getRMW(); + + //If the fromnode has a rmwnode that is not the tonode, we + //should add an edge between its rmwnode and the tonode + + if (rmwnode!=NULL&&rmwnode!=tonode) { + if (!hasCycles) { + // Check for Cycles + hasCycles=checkReachable(tonode, rmwnode); + } + rmwnode->addEdge(tonode); + } +} + +//event rmw that reads from the node from + +void CycleGraph::addRMWEdge(const ModelAction *rmw, const ModelAction * from) { + CycleNode *fromnode=getNode(from); + CycleNode *rmwnode=getNode(rmw); + + /* Two RMW actions cannot read from the same write. */ + if (fromnode->setRMW(rmwnode)) { + hasCycles=true; + } + + /* Transfer all outgoing edges from the from node to the rmw node */ + /* This process cannot add a cycle because rmw should not have any + incoming edges yet.*/ + std::vector * edges=fromnode->getEdges(); + for(unsigned int i=0;isize();i++) { + CycleNode * tonode=(*edges)[i]; + rmwnode->addEdge(tonode); + } + + fromnode->addEdge(rmwnode); } + /** Checks whether the first CycleNode can reach the second one. */ bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { std::vector queue; @@ -57,8 +101,9 @@ bool CycleGraph::checkForCycles() { } /** Constructor for a CycleNode. */ -CycleNode::CycleNode(ModelAction *modelaction) { +CycleNode::CycleNode(const ModelAction *modelaction) { action=modelaction; + hasRMW=NULL; } /** Returns a vector of the edges from a CycleNode. */ @@ -70,3 +115,13 @@ std::vector * CycleNode::getEdges() { void CycleNode::addEdge(CycleNode * node) { edges.push_back(node); } + +CycleNode* CycleNode::getRMW() { + return hasRMW; +} + +bool CycleNode::setRMW(CycleNode * node) { + CycleNode * oldhasRMW=hasRMW; + hasRMW=node; + return (oldhasRMW!=NULL); +}