864ce8f45aad5fc8cb885492420ea408881cba69
[c11tester.git] / tree.h
1 #ifndef __TREE_H__
2 #define __TREE_H__
3
4 #include <set>
5 #include <map>
6 #include <cstddef>
7 #include "threads.h"
8
9 class ModelAction;
10
11 /*
12  * An n-ary tree
13  *
14  * A tree with n possible branches from each node - used for recording the
15  * execution paths we've executed / backtracked
16  */
17 class TreeNode {
18 public:
19         TreeNode(TreeNode *par = NULL, ModelAction *act = NULL);
20         ~TreeNode();
21         bool hasBeenExplored(thread_id_t id) { return children.find(id_to_int(id)) != children.end(); }
22         TreeNode * explore_child(ModelAction *act);
23         thread_id_t getNextBacktrack();
24
25         /* Return 1 if already in backtrack, 0 otherwise */
26         int setBacktrack(thread_id_t id);
27         TreeNode * getRoot();
28         static int getTotalNodes() { return TreeNode::totalNodes; }
29
30         bool is_enabled(Thread *t);
31 private:
32         TreeNode *parent;
33         std::map<int, class TreeNode *> children;
34         std::set<int> backtrack;
35         static int totalNodes;
36         int num_threads;
37 };
38
39 #endif /* __TREE_H__ */