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 typedef std::vector< const Promise *, ModelAlloc<const Promise *> > promise_list_t;
24 /** @brief A graph of Model Actions for tracking cycles. */
30 template <typename T, typename U>
31 bool addEdge(const T *from, const U *to);
34 void addRMWEdge(const T *from, const ModelAction *rmw);
36 bool checkForCycles() const;
37 bool checkPromise(const ModelAction *from, Promise *p) const;
39 template <typename T, typename U>
40 bool checkReachable(const T *from, const U *to) const;
44 void rollbackChanges();
45 #if SUPPORT_MOD_ORDER_DUMP
46 void dumpNodes(FILE *file) const;
47 void dumpGraphToFile(const char *filename) const;
50 bool resolvePromise(const Promise *promise, ModelAction *writer,
51 promise_list_t *mustResolve);
55 bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
56 void putNode(const ModelAction *act, CycleNode *node);
57 void putNode(const Promise *promise, CycleNode *node);
58 void erasePromiseNode(const Promise *promise);
59 CycleNode * getNode(const ModelAction *act);
60 CycleNode * getNode(const Promise *promise);
61 CycleNode * getNode_noCreate(const ModelAction *act) const;
62 CycleNode * getNode_noCreate(const Promise *promise) const;
63 bool mergeNodes(CycleNode *node1, CycleNode *node2,
64 promise_list_t *mustMerge);
66 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
68 /** @brief A table for mapping ModelActions to CycleNodes */
69 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
70 /** @brief A table for mapping Promises to CycleNodes */
71 HashTable<const Promise *, CycleNode *, uintptr_t, 4> promiseToNode;
73 #if SUPPORT_MOD_ORDER_DUMP
74 std::vector<CycleNode *> nodeList;
77 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
79 /** @brief A flag: true if this graph contains cycles */
83 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
84 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
88 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
89 * to a promised future value
93 CycleNode(const ModelAction *act);
94 CycleNode(const Promise *promise);
95 bool addEdge(CycleNode *node);
96 CycleNode * getEdge(unsigned int i) const;
97 unsigned int getNumEdges() const;
98 CycleNode * getBackEdge(unsigned int i) const;
99 unsigned int getNumBackEdges() const;
100 CycleNode * removeEdge();
101 CycleNode * removeBackEdge();
103 bool setRMW(CycleNode *);
104 CycleNode * getRMW() const;
105 void clearRMW() { hasRMW = NULL; }
106 const ModelAction * getAction() const { return action; }
107 const Promise * getPromise() const { return promise; }
108 bool is_promise() const { return !action; }
109 void resolvePromise(const ModelAction *writer);
113 /** @brief The ModelAction that this node represents */
114 const ModelAction *action;
116 /** @brief The promise represented by this node; only valid when action
118 const Promise *promise;
120 /** @brief The edges leading out from this node */
121 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
123 /** @brief The edges leading into this node */
124 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
126 /** Pointer to a RMW node that reads from this node, or NULL, if none
131 #endif /* __CYCLEGRAPH_H__ */