+#if SUPPORT_MOD_ORDER_DUMP
+void CycleGraph::dumpNodes(FILE *file) const
+{
+ for (unsigned int i = 0; i < nodeList.size(); i++) {
+ CycleNode *cn = nodeList[i];
+ const ModelAction *action = cn->getAction();
+ fprintf(file, "N%u [label=\"%u, T%u\"];\n", action->get_seq_number(), action->get_seq_number(), action->get_tid());
+ if (cn->getRMW() != NULL) {
+ fprintf(file, "N%u -> N%u[style=dotted];\n", action->get_seq_number(), cn->getRMW()->getAction()->get_seq_number());
+ }
+ for (unsigned int j = 0; j < cn->getNumEdges(); j++) {
+ CycleNode *dst = cn->getEdge(j);
+ const ModelAction *dstaction = dst->getAction();
+ fprintf(file, "N%u -> N%u;\n", action->get_seq_number(), dstaction->get_seq_number());
+ }
+ }
+}
+
+void CycleGraph::dumpGraphToFile(const char *filename) const
+{
+ char buffer[200];
+ sprintf(buffer, "%s.dot", filename);
+ FILE *file = fopen(buffer, "w");
+ fprintf(file, "digraph %s {\n", filename);
+ dumpNodes(file);
+ fprintf(file, "}\n");
+ fclose(file);
+}
+#endif
+
+/**
+ * Checks whether one CycleNode can reach another.
+ * @param from The CycleNode from which to begin exploration
+ * @param to The CycleNode to reach
+ * @return True, @a from can reach @a to; otherwise, false
+ */
+bool CycleGraph::checkReachable(const CycleNode *from, const CycleNode *to) const
+{
+ std::vector< const CycleNode *, ModelAlloc<const CycleNode *> > queue;
+ discovered->reset();
+
+ queue.push_back(from);
+ discovered->put(from, from);
+ 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);
+ }
+ }
+ }
+ return false;
+}