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 *);
56 CycleNode * getNode(const Promise *promise);
57 bool mergeNodes(CycleNode *node1, CycleNode *node2,
58 promise_list_t *mustMerge);
60 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
62 /** @brief A table for mapping ModelActions to CycleNodes */
63 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
64 /** @brief A table for mapping reader ModelActions to Promise
66 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
68 #if SUPPORT_MOD_ORDER_DUMP
69 std::vector<CycleNode *> nodeList;
72 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
74 /** @brief A flag: true if this graph contains cycles */
78 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
79 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
83 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
84 * to a promised future value
88 CycleNode(const ModelAction *act);
89 CycleNode(const Promise *promise);
90 bool addEdge(CycleNode *node);
91 CycleNode * getEdge(unsigned int i) const;
92 unsigned int getNumEdges() const;
93 CycleNode * getBackEdge(unsigned int i) const;
94 unsigned int getNumBackEdges() const;
95 CycleNode * removeEdge();
96 CycleNode * removeBackEdge();
98 bool setRMW(CycleNode *);
99 CycleNode * getRMW() const;
100 void clearRMW() { hasRMW = NULL; }
101 const ModelAction * getAction() const { return action; }
102 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__ */