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(ModelAction *reader, 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 reader ModelActions to Promise
72 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
74 #if SUPPORT_MOD_ORDER_DUMP
75 std::vector<CycleNode *> nodeList;
78 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
80 /** @brief A flag: true if this graph contains cycles */
84 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
85 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
89 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
90 * to a promised future value
94 CycleNode(const ModelAction *act);
95 CycleNode(const Promise *promise);
96 bool addEdge(CycleNode *node);
97 CycleNode * getEdge(unsigned int i) const;
98 unsigned int getNumEdges() const;
99 CycleNode * getBackEdge(unsigned int i) const;
100 unsigned int getNumBackEdges() const;
101 CycleNode * removeEdge();
102 CycleNode * removeBackEdge();
104 bool setRMW(CycleNode *);
105 CycleNode * getRMW() const;
106 void clearRMW() { hasRMW = NULL; }
107 const ModelAction * getAction() const { return action; }
108 const Promise * getPromise() const { return promise; }
109 bool is_promise() const { return !action; }
110 void resolvePromise(const ModelAction *writer);
114 /** @brief The ModelAction that this node represents */
115 const ModelAction *action;
117 /** @brief The promise represented by this node; only valid when action
119 const Promise *promise;
121 /** @brief The edges leading out from this node */
122 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
124 /** @brief The edges leading into this node */
125 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
127 /** Pointer to a RMW node that reads from this node, or NULL, if none
132 #endif /* __CYCLEGRAPH_H__ */