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;
36 bool checkReachable(const ModelAction *from, const ModelAction *to) const;
39 void rollbackChanges();
40 #if SUPPORT_MOD_ORDER_DUMP
41 void dumpNodes(FILE *file) const;
42 void dumpGraphToFile(const char *filename) const;
45 bool resolvePromise(ModelAction *reader, ModelAction *writer,
46 promise_list_t *mustResolve);
50 void addNodeEdge(CycleNode *fromnode, CycleNode *tonode);
51 void putNode(const ModelAction *act, CycleNode *node);
52 CycleNode * getNode(const ModelAction *);
53 CycleNode * getNode(const Promise *promise);
54 bool mergeNodes(CycleNode *node1, CycleNode *node2,
55 promise_list_t *mustMerge);
57 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
59 /** @brief A table for mapping ModelActions to CycleNodes */
60 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
61 /** @brief A table for mapping reader ModelActions to Promise
63 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
65 #if SUPPORT_MOD_ORDER_DUMP
66 std::vector<CycleNode *> nodeList;
69 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
71 /** @brief A flag: true if this graph contains cycles */
75 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
76 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
80 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
81 * to a promised future value
85 CycleNode(const ModelAction *act);
86 CycleNode(const Promise *promise);
87 bool addEdge(CycleNode *node);
88 CycleNode * getEdge(unsigned int i) const;
89 unsigned int getNumEdges() const;
90 CycleNode * getBackEdge(unsigned int i) const;
91 unsigned int getNumBackEdges() const;
92 CycleNode * removeEdge();
93 CycleNode * removeBackEdge();
95 bool setRMW(CycleNode *);
96 CycleNode * getRMW() const;
97 void clearRMW() { hasRMW = NULL; }
98 const ModelAction * getAction() const { return action; }
99 const Promise * getPromise() const { return promise; }
105 bool is_promise() const { return !action; }
106 void resolvePromise(const ModelAction *writer);
110 /** @brief The ModelAction that this node represents */
111 const ModelAction *action;
113 /** @brief The promise represented by this node; only valid when action
115 const Promise *promise;
117 /** @brief The edges leading out from this node */
118 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
120 /** @brief The edges leading into this node */
121 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
123 /** Pointer to a RMW node that reads from this node, or NULL, if none
128 #endif /* __CYCLEGRAPH_H__ */