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. */
28 template <typename T, typename U>
29 void addEdge(const T from, const U to);
31 bool checkForCycles() const;
32 void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
33 bool checkPromise(const ModelAction *from, Promise *p) const;
34 bool checkReachable(const ModelAction *from, const ModelAction *to) const;
37 void rollbackChanges();
38 #if SUPPORT_MOD_ORDER_DUMP
39 void dumpNodes(FILE *file) const;
40 void dumpGraphToFile(const char *filename) const;
45 void addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
46 void putNode(const ModelAction *act, CycleNode *node);
47 CycleNode * getNode(const ModelAction *);
48 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
50 /** @brief A table for mapping ModelActions to CycleNodes */
51 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
52 #if SUPPORT_MOD_ORDER_DUMP
53 std::vector<CycleNode *> nodeList;
56 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
58 /** @brief A flag: true if this graph contains cycles */
62 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
63 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
67 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
68 * to a promised future value
72 CycleNode(const ModelAction *act);
73 CycleNode(const Promise *promise);
74 bool addEdge(CycleNode *node);
75 CycleNode * getEdge(unsigned int i) const;
76 unsigned int getNumEdges() const;
77 CycleNode * getBackEdge(unsigned int i) const;
78 unsigned int getNumBackEdges() const;
79 CycleNode * removeEdge();
80 CycleNode * removeBackEdge();
82 bool setRMW(CycleNode *);
83 CycleNode * getRMW() const;
84 void clearRMW() { hasRMW = NULL; }
85 const ModelAction * getAction() const { return action; }
91 bool is_promise() const { return !action; }
95 /** @brief The ModelAction that this node represents */
96 const ModelAction *action;
98 /** @brief The promise represented by this node; only valid when action
100 const Promise *promise;
102 /** @brief The edges leading out from this node */
103 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
105 /** @brief The edges leading into this node */
106 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
108 /** Pointer to a RMW node that reads from this node, or NULL, if none
113 #endif /* __CYCLEGRAPH_H__ */