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 void addEdge(const T from, const U to);
33 bool checkForCycles() const;
34 void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
35 bool checkPromise(const ModelAction *from, Promise *p) const;
38 bool checkReachable(const ModelAction *from, const T *to) const;
42 void rollbackChanges();
43 #if SUPPORT_MOD_ORDER_DUMP
44 void dumpNodes(FILE *file) const;
45 void dumpGraphToFile(const char *filename) const;
48 bool resolvePromise(ModelAction *reader, ModelAction *writer,
49 promise_list_t *mustResolve);
53 void addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
54 void putNode(const ModelAction *act, CycleNode *node);
55 CycleNode * getNode(const ModelAction *act);
56 CycleNode * getNode(const Promise *promise);
57 CycleNode * getNode_noCreate(const ModelAction *act) const;
58 CycleNode * getNode_noCreate(const Promise *promise) const;
59 bool mergeNodes(CycleNode *node1, CycleNode *node2,
60 promise_list_t *mustMerge);
62 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
64 /** @brief A table for mapping ModelActions to CycleNodes */
65 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
66 /** @brief A table for mapping reader ModelActions to Promise
68 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
70 #if SUPPORT_MOD_ORDER_DUMP
71 std::vector<CycleNode *> nodeList;
74 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
76 /** @brief A flag: true if this graph contains cycles */
80 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
81 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
85 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
86 * to a promised future value
90 CycleNode(const ModelAction *act);
91 CycleNode(const Promise *promise);
92 bool addEdge(CycleNode *node);
93 CycleNode * getEdge(unsigned int i) const;
94 unsigned int getNumEdges() const;
95 CycleNode * getBackEdge(unsigned int i) const;
96 unsigned int getNumBackEdges() const;
97 CycleNode * removeEdge();
98 CycleNode * removeBackEdge();
100 bool setRMW(CycleNode *);
101 CycleNode * getRMW() const;
102 void clearRMW() { hasRMW = NULL; }
103 const ModelAction * getAction() const { return action; }
104 const Promise * getPromise() const { return promise; }
110 bool is_promise() const { return !action; }
111 void resolvePromise(const ModelAction *writer);
115 /** @brief The ModelAction that this node represents */
116 const ModelAction *action;
118 /** @brief The promise represented by this node; only valid when action
120 const Promise *promise;
122 /** @brief The edges leading out from this node */
123 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
125 /** @brief The edges leading into this node */
126 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
128 /** Pointer to a RMW node that reads from this node, or NULL, if none
133 #endif /* __CYCLEGRAPH_H__ */