deal with looping due to bogus future value via promise expiration
[c11tester.git] / cyclegraph.h
1 /** @file cyclegraph.h @brief Data structure to track ordering
2  *  constraints on modification order.  The idea is to see whether a
3  *  total order exists that satisfies the ordering constriants.*/
4
5 #ifndef CYCLEGRAPH_H
6 #define CYCLEGRAPH_H
7
8 #include "hashtable.h"
9 #include <vector>
10 #include <inttypes.h>
11
12 class CycleNode;
13 class ModelAction;
14
15 /** @brief A graph of Model Actions for tracking cycles. */
16 class CycleGraph {
17  public:
18         CycleGraph();
19         ~CycleGraph();
20         void addEdge(const ModelAction *from, const ModelAction *to);
21         bool checkForCycles();
22         void addRMWEdge(const ModelAction *from, const ModelAction *rmw);
23
24         bool checkReachable(const ModelAction *from, const ModelAction *to);
25         void commitChanges();
26         void rollbackChanges();
27
28  private:
29         CycleNode * getNode(const ModelAction *);
30
31         /** @brief A table for mapping ModelActions to CycleNodes */
32         HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
33
34         bool checkReachable(CycleNode *from, CycleNode *to);
35
36         /** @brief A flag: true if this graph contains cycles */
37         bool hasCycles;
38
39         bool oldCycles;
40
41         std::vector<CycleNode *> rollbackvector;
42         std::vector<CycleNode *> rmwrollbackvector;
43 };
44
45 /** @brief A node within a CycleGraph; corresponds to one ModelAction */
46 class CycleNode {
47  public:
48         CycleNode(const ModelAction *action);
49         void addEdge(CycleNode * node);
50         std::vector<CycleNode *> * getEdges();
51         bool setRMW(CycleNode *);
52         CycleNode* getRMW();
53         void popEdge() {
54                 edges.pop_back();
55         };
56         void clearRMW() {
57                 hasRMW=NULL;
58         }
59
60  private:
61         /** @brief The ModelAction that this node represents */
62         const ModelAction *action;
63
64         /** @brief The edges leading out from this node */
65         std::vector<CycleNode *> edges;
66
67         /** Pointer to a RMW node that reads from this node, or NULL, if none
68          * exists */
69         CycleNode * hasRMW;
70 };
71
72 #endif