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"
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;
49 void dot_print_node(FILE *file, const ModelAction *act);
50 template <typename T, typename U>
51 void dot_print_edge(FILE *file, const T *from, const U *to, const char *prop);
54 bool resolvePromise(const Promise *promise, ModelAction *writer);
58 bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
59 void putNode(const ModelAction *act, CycleNode *node);
60 void putNode(const Promise *promise, CycleNode *node);
61 void erasePromiseNode(const Promise *promise);
62 CycleNode * getNode(const ModelAction *act);
63 CycleNode * getNode(const Promise *promise);
64 CycleNode * getNode_noCreate(const ModelAction *act) const;
65 CycleNode * getNode_noCreate(const Promise *promise) const;
66 bool mergeNodes(CycleNode *node1, CycleNode *node2);
68 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
69 ModelVector<const CycleNode *> * queue;
72 /** @brief A table for mapping ModelActions to CycleNodes */
73 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
74 /** @brief A table for mapping Promises to CycleNodes */
75 HashTable<const Promise *, CycleNode *, uintptr_t, 4> promiseToNode;
77 #if SUPPORT_MOD_ORDER_DUMP
78 SnapVector<CycleNode *> nodeList;
81 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
83 /** @brief A flag: true if this graph contains cycles */
85 /** @brief The previous value of CycleGraph::hasCycles, for rollback */
88 SnapVector<CycleNode *> rollbackvector;
89 SnapVector<CycleNode *> rmwrollbackvector;
93 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
94 * to a promised future value
98 CycleNode(const ModelAction *act);
99 CycleNode(const Promise *promise);
100 bool addEdge(CycleNode *node);
101 CycleNode * getEdge(unsigned int i) const;
102 unsigned int getNumEdges() const;
103 CycleNode * getBackEdge(unsigned int i) const;
104 unsigned int getNumBackEdges() const;
105 CycleNode * removeEdge();
106 CycleNode * removeBackEdge();
108 bool setRMW(CycleNode *);
109 CycleNode * getRMW() const;
110 void clearRMW() { hasRMW = NULL; }
111 const ModelAction * getAction() const { return action; }
112 const Promise * getPromise() const { return promise; }
113 bool is_promise() const { return !action; }
114 void resolvePromise(const ModelAction *writer);
118 /** @brief The ModelAction that this node represents */
119 const ModelAction *action;
121 /** @brief The promise represented by this node; only valid when action
123 const Promise *promise;
125 /** @brief The edges leading out from this node */
126 SnapVector<CycleNode *> edges;
128 /** @brief The edges leading into this node */
129 SnapVector<CycleNode *> back_edges;
131 /** Pointer to a RMW node that reads from this node, or NULL, if none
136 #endif /* __CYCLEGRAPH_H__ */