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;
40 bool checkReachable(const ModelAction *from, const T *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 CycleNode * getNode(const ModelAction *act);
58 CycleNode * getNode(const Promise *promise);
59 CycleNode * getNode_noCreate(const ModelAction *act) const;
60 CycleNode * getNode_noCreate(const Promise *promise) const;
61 bool mergeNodes(CycleNode *node1, CycleNode *node2,
62 promise_list_t *mustMerge);
64 HashTable<const CycleNode *, const CycleNode *, uintptr_t, 4, model_malloc, model_calloc, model_free> *discovered;
66 /** @brief A table for mapping ModelActions to CycleNodes */
67 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
68 /** @brief A table for mapping reader ModelActions to Promise
70 HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> readerToPromiseNode;
72 #if SUPPORT_MOD_ORDER_DUMP
73 std::vector<CycleNode *> nodeList;
76 bool checkReachable(const CycleNode *from, const CycleNode *to) const;
78 /** @brief A flag: true if this graph contains cycles */
82 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rollbackvector;
83 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > rmwrollbackvector;
87 * @brief A node within a CycleGraph; corresponds either to one ModelAction or
88 * to a promised future value
92 CycleNode(const ModelAction *act);
93 CycleNode(const Promise *promise);
94 bool addEdge(CycleNode *node);
95 CycleNode * getEdge(unsigned int i) const;
96 unsigned int getNumEdges() const;
97 CycleNode * getBackEdge(unsigned int i) const;
98 unsigned int getNumBackEdges() const;
99 CycleNode * removeEdge();
100 CycleNode * removeBackEdge();
102 bool setRMW(CycleNode *);
103 CycleNode * getRMW() const;
104 void clearRMW() { hasRMW = NULL; }
105 const ModelAction * getAction() const { return action; }
106 const Promise * getPromise() const { return promise; }
107 bool is_promise() const { return !action; }
108 void resolvePromise(const ModelAction *writer);
112 /** @brief The ModelAction that this node represents */
113 const ModelAction *action;
115 /** @brief The promise represented by this node; only valid when action
117 const Promise *promise;
119 /** @brief The edges leading out from this node */
120 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > edges;
122 /** @brief The edges leading into this node */
123 std::vector< CycleNode *, SnapshotAlloc<CycleNode *> > back_edges;
125 /** Pointer to a RMW node that reads from this node, or NULL, if none
130 #endif /* __CYCLEGRAPH_H__ */