cyclegraph: possible optimization
[c11tester.git] / cyclegraph.cc
index e0b221514f9bd88b0785839b44e2436921f9f4b8..44f5a28bc15b69cc3289a4906b298341845ae324 100644 (file)
@@ -308,10 +308,11 @@ bool CycleGraph::addEdge(const T *from, const U *to)
 
        return addNodeEdge(fromnode, tonode);
 }
 
        return addNodeEdge(fromnode, tonode);
 }
-/* Instantiate three forms of CycleGraph::addEdge */
+/* Instantiate four forms of CycleGraph::addEdge */
 template bool CycleGraph::addEdge(const ModelAction *from, const ModelAction *to);
 template bool CycleGraph::addEdge(const ModelAction *from, const Promise *to);
 template bool CycleGraph::addEdge(const Promise *from, const ModelAction *to);
 template bool CycleGraph::addEdge(const ModelAction *from, const ModelAction *to);
 template bool CycleGraph::addEdge(const ModelAction *from, const Promise *to);
 template bool CycleGraph::addEdge(const Promise *from, const ModelAction *to);
+template bool CycleGraph::addEdge(const Promise *from, const Promise *to);
 
 #if SUPPORT_MOD_ORDER_DUMP
 
 
 #if SUPPORT_MOD_ORDER_DUMP
 
@@ -405,13 +406,13 @@ bool CycleGraph::checkReachable(const CycleNode *from, const CycleNode *to) cons
 }
 
 /**
 }
 
 /**
- * Checks whether one ModelAction can reach another ModelAction/Promise
- * @param from The ModelAction from which to begin exploration
+ * Checks whether one ModelAction/Promise can reach another ModelAction/Promise
+ * @param from The ModelAction or Promise from which to begin exploration
  * @param to The ModelAction or Promise to reach
  * @return True, @a from can reach @a to; otherwise, false
  */
  * @param to The ModelAction or Promise to reach
  * @return True, @a from can reach @a to; otherwise, false
  */
-template <typename T>
-bool CycleGraph::checkReachable(const ModelAction *from, const T *to) const
+template <typename T, typename U>
+bool CycleGraph::checkReachable(const T *from, const U *to) const
 {
        CycleNode *fromnode = getNode_noCreate(from);
        CycleNode *tonode = getNode_noCreate(to);
 {
        CycleNode *fromnode = getNode_noCreate(from);
        CycleNode *tonode = getNode_noCreate(to);
@@ -421,11 +422,13 @@ bool CycleGraph::checkReachable(const ModelAction *from, const T *to) const
 
        return checkReachable(fromnode, tonode);
 }
 
        return checkReachable(fromnode, tonode);
 }
-/* Instantiate two forms of CycleGraph::checkReachable */
+/* Instantiate three 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 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;
 
 /** @return True, if the promise has failed; false otherwise */
 bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) const
 
 /** @return True, if the promise has failed; false otherwise */
 bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) const
@@ -440,6 +443,8 @@ bool CycleGraph::checkPromise(const ModelAction *fromact, Promise *promise) cons
                CycleNode *node = queue.back();
                queue.pop_back();
 
                CycleNode *node = queue.back();
                queue.pop_back();
 
+               if (node->getPromise() == promise)
+                       return true;
                if (!node->is_promise() &&
                                promise->eliminate_thread(node->getAction()->get_tid()))
                        return true;
                if (!node->is_promise() &&
                                promise->eliminate_thread(node->getAction()->get_tid()))
                        return true;