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__
12 #include "hashtable.h"
22 /** @brief A graph of Model Actions for tracking cycles. */
27 void addEdge(const ModelAction *from, const ModelAction *to);
28 bool checkForCycles() const;
29 bool checkForRMWViolation() const;
30 void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
31 bool checkPromise(const ModelAction *from, Promise *p) const;
32 bool checkReachable(const ModelAction *from, const ModelAction *to) const;
35 void rollbackChanges();
36 #if SUPPORT_MOD_ORDER_DUMP
37 void dumpNodes(FILE *file) const;
38 void dumpGraphToFile(const char *filename) const;
43 void addEdge(CycleNode *fromnode, CycleNode *tonode);
44 void putNode(const ModelAction *act, CycleNode *node);
45 CycleNode * getNode(const ModelAction *);
46 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
48 /** @brief A table for mapping ModelActions to CycleNodes */
49 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
50 #if SUPPORT_MOD_ORDER_DUMP
51 std::vector<CycleNode *> nodeList;
54 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
56 /** @brief A flag: true if this graph contains cycles */
63 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
64 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
67 /** @brief A node within a CycleGraph; corresponds to one ModelAction */
70 CycleNode(const ModelAction *act);
71 bool addEdge(CycleNode *node);
72 CycleNode * getEdge(unsigned int i) const;
73 unsigned int getNumEdges() const;
74 CycleNode * getBackEdge(unsigned int i) const;
75 unsigned int getNumBackEdges() const;
76 bool setRMW(CycleNode *);
77 CycleNode * getRMW() const;
78 const ModelAction * getAction() const { return action; }
89 /** @brief The ModelAction that this node represents */
90 const ModelAction *action;
92 /** @brief The edges leading out from this node */
93 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
95 /** @brief The edges leading into this node */
96 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
98 /** Pointer to a RMW node that reads from this node, or NULL, if none
103 #endif /* __CYCLEGRAPH_H__ */