3 * @brief Data structure to track ordering constraints on modification order
5 * Used to determine whether a total order exists that satisfies the ordering
9 #ifndef __CYCLEGRAPH_H__
10 #define __CYCLEGRAPH_H__
15 #include "hashtable.h"
18 #include "stl-model.h"
19 #include "classlist.h"
21 /** @brief A graph of Model Actions for tracking cycles. */
27 template <typename T, typename U>
28 bool addEdge(const T *from, const U *to);
31 void addRMWEdge(const T *from, const ModelAction *rmw);
33 bool checkForCycles() const;
35 template <typename T, typename U>
36 bool checkReachable(const T *from, const U *to) const;
40 void rollbackChanges();
41 #if SUPPORT_MOD_ORDER_DUMP
42 void dumpNodes(FILE *file) const;
43 void dumpGraphToFile(const char *filename) const;
45 void dot_print_node(FILE *file, const ModelAction *act);
46 template <typename T, typename U>
47 void dot_print_edge(FILE *file, const T *from, const U *to, const char *prop);
53 bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
54 void putNode(const ModelAction *act, CycleNode *node);
55 CycleNode * getNode(const ModelAction *act);
56 CycleNode * getNode_noCreate(const ModelAction *act) const;
57 bool mergeNodes(CycleNode *node1, CycleNode *node2);
59 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
60 ModelVector<const CycleNode *> * queue;
63 /** @brief A table for mapping ModelActions to CycleNodes */
64 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
66 #if SUPPORT_MOD_ORDER_DUMP
67 SnapVector<CycleNode *> nodeList;
70 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
72 /** @brief A flag: true if this graph contains cycles */
74 /** @brief The previous value of CycleGraph::hasCycles, for rollback */
77 SnapVector<CycleNode *> rollbackvector;
78 SnapVector<CycleNode *> rmwrollbackvector;
82 * @brief A node within a CycleGraph; corresponds either to one ModelAction
86 CycleNode(const ModelAction *act);
87 bool addEdge(CycleNode *node);
88 CycleNode * getEdge(unsigned int i) const;
89 unsigned int getNumEdges() const;
90 CycleNode * getBackEdge(unsigned int i) const;
91 unsigned int getNumBackEdges() const;
92 CycleNode * removeEdge();
93 CycleNode * removeBackEdge();
95 bool setRMW(CycleNode *);
96 CycleNode * getRMW() const;
97 void clearRMW() { hasRMW = NULL; }
98 const ModelAction * getAction() const { return action; }
102 /** @brief The ModelAction that this node represents */
103 const ModelAction *action;
105 /** @brief The edges leading out from this node */
106 SnapVector<CycleNode *> edges;
108 /** @brief The edges leading into this node */
109 SnapVector<CycleNode *> back_edges;
111 /** Pointer to a RMW node that reads from this node, or NULL, if none
116 #endif /* __CYCLEGRAPH_H__ */