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 CycleNode * getNode(const Promise *promise);
50 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
52 /** @brief A table for mapping ModelActions to CycleNodes */
53 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
54 /** @brief A table for mapping reader ModelActions to Promise
56 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
58 #if SUPPORT_MOD_ORDER_DUMP
59 std::vector<CycleNode *> nodeList;
62 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
64 /** @brief A flag: true if this graph contains cycles */
68 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
69 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
73 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
74 * to a promised future value
78 CycleNode(const ModelAction *act);
79 CycleNode(const Promise *promise);
80 bool addEdge(CycleNode *node);
81 CycleNode * getEdge(unsigned int i) const;
82 unsigned int getNumEdges() const;
83 CycleNode * getBackEdge(unsigned int i) const;
84 unsigned int getNumBackEdges() const;
85 CycleNode * removeEdge();
86 CycleNode * removeBackEdge();
88 bool setRMW(CycleNode *);
89 CycleNode * getRMW() const;
90 void clearRMW() { hasRMW = NULL; }
91 const ModelAction * getAction() const { return action; }
97 bool is_promise() const { return !action; }
101 /** @brief The ModelAction that this node represents */
102 const ModelAction *action;
104 /** @brief The promise represented by this node; only valid when action
106 const Promise *promise;
108 /** @brief The edges leading out from this node */
109 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
111 /** @brief The edges leading into this node */
112 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
114 /** Pointer to a RMW node that reads from this node, or NULL, if none
119 #endif /* __CYCLEGRAPH_H__ */