test/Makefile: remove pointless variable
[model-checker.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 *to);
23
24  private:
25         CycleNode * getNode(const ModelAction *);
26
27         /** @brief A table for mapping ModelActions to CycleNodes */
28         HashTable<const ModelAction *, CycleNode *, uintptr_t, 4> actionToNode;
29
30         bool checkReachable(CycleNode *from, CycleNode *to);
31
32         /** @brief A flag: true if this graph contains cycles */
33         bool hasCycles;
34 };
35
36 /** @brief A node within a CycleGraph; corresponds to one ModelAction */
37 class CycleNode {
38  public:
39         CycleNode(const ModelAction *action);
40         void addEdge(CycleNode * node);
41         std::vector<CycleNode *> * getEdges();
42         bool setRMW(CycleNode *);
43         CycleNode* getRMW();
44
45  private:
46         /** @brief The ModelAction that this node represents */
47         const ModelAction *action;
48
49         /** @brief The edges leading out from this node */
50         std::vector<CycleNode *> edges;
51
52         /** Pointer to a RMW node that reads from this node, or NULL, if none
53          * exists */
54         CycleNode * hasRMW;
55 };
56
57 #endif