cyclegraph: add Promise CycleNode
[c11tester.git] / cyclegraph.cc
index 62cef7c56079e2d2a46587a181340320a9fe0405..7a3532830598684a7719f6f3329fcda746aa5ccc 100644 (file)
@@ -8,9 +8,7 @@
 CycleGraph::CycleGraph() :
        discovered(new HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free>(16)),
        hasCycles(false),
-       oldCycles(false),
-       hasRMWViolation(false),
-       oldRMWViolation(false)
+       oldCycles(false)
 {
 }
 
@@ -92,10 +90,17 @@ void CycleGraph::addEdge(CycleNode *fromnode, CycleNode *tonode)
        }
 }
 
-/** Handles special case of a RMW action.  The ModelAction rmw reads
- *  from the ModelAction from.  The key differences are: (1) no write
- *  can occur in between the rmw and the from action.  Only one RMW
- *  action can read from a given write.
+/**
+ * @brief Add an edge between a write and the RMW which reads from it
+ *
+ * Handles special case of a RMW action, where the ModelAction rmw reads from
+ * the ModelAction from. The key differences are:
+ * (1) no write can occur in between the rmw and the from action.
+ * (2) Only one RMW action can read from a given write.
+ *
+ * @param from The edge comes from this ModelAction
+ * @param rmw The edge points to this ModelAction; this action must read from
+ * ModelAction from
  */
 void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw)
 {
@@ -106,11 +111,10 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw)
        CycleNode *rmwnode = getNode(rmw);
 
        /* Two RMW actions cannot read from the same write. */
-       if (fromnode->setRMW(rmwnode)) {
-               hasRMWViolation = true;
-       } else {
+       if (fromnode->setRMW(rmwnode))
+               hasCycles = true;
+       else
                rmwrollbackvector.push_back(fromnode);
-       }
 
        /* Transfer all outgoing edges from the from node to the rmw node */
        /* This process should not add a cycle because either:
@@ -236,36 +240,31 @@ bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) cons
 
 void CycleGraph::startChanges()
 {
-       ASSERT(rollbackvector.size() == 0);
-       ASSERT(rmwrollbackvector.size() == 0);
+       ASSERT(rollbackvector.empty());
+       ASSERT(rmwrollbackvector.empty());
        ASSERT(oldCycles == hasCycles);
-       ASSERT(oldRMWViolation == hasRMWViolation);
 }
 
 /** Commit changes to the cyclegraph. */
 void CycleGraph::commitChanges()
 {
-       rollbackvector.resize(0);
-       rmwrollbackvector.resize(0);
+       rollbackvector.clear();
+       rmwrollbackvector.clear();
        oldCycles = hasCycles;
-       oldRMWViolation = hasRMWViolation;
 }
 
 /** Rollback changes to the previous commit. */
 void CycleGraph::rollbackChanges()
 {
-       for (unsigned int i = 0; i < rollbackvector.size(); i++) {
+       for (unsigned int i = 0; i < rollbackvector.size(); i++)
                rollbackvector[i]->popEdge();
-       }
 
-       for (unsigned int i = 0; i < rmwrollbackvector.size(); i++) {
+       for (unsigned int i = 0; i < rmwrollbackvector.size(); i++)
                rmwrollbackvector[i]->clearRMW();
-       }
 
        hasCycles = oldCycles;
-       hasRMWViolation = oldRMWViolation;
-       rollbackvector.resize(0);
-       rmwrollbackvector.resize(0);
+       rollbackvector.clear();
+       rmwrollbackvector.clear();
 }
 
 /** @returns whether a CycleGraph contains cycles. */
@@ -274,17 +273,24 @@ bool CycleGraph::checkForCycles() const
        return hasCycles;
 }
 
-bool CycleGraph::checkForRMWViolation() const
-{
-       return hasRMWViolation;
-}
-
 /**
  * @brief Constructor for a CycleNode
  * @param act The ModelAction for this node
  */
 CycleNode::CycleNode(const ModelAction *act) :
        action(act),
+       promise(NULL),
+       hasRMW(NULL)
+{
+}
+
+/**
+ * @brief Constructor for a Promise CycleNode
+ * @param promise The Promise which was generated
+ */
+CycleNode::CycleNode(const Promise *promise) :
+       action(NULL),
+       promise(promise),
        hasRMW(NULL)
 {
 }