Adding relevant comments for fork based implementation.
[c11tester.git] / nodestack.h
1 /** @file nodestack.h
2  *  @brief Stack of operations for use in backtracking.
3 */
4
5 #ifndef __NODESTACK_H__
6 #define __NODESTACK_H__
7
8 #include <list>
9 #include <vector>
10 #include <set>
11 #include <cstddef>
12 #include "threads.h"
13 #include "mymemory.h"
14
15 class ModelAction;
16
17 typedef std::set< ModelAction *, std::less< ModelAction *>, MyAlloc< ModelAction * > > action_set_t;
18
19 class Node {
20 public:
21         Node(ModelAction *act = NULL, int nthreads = 1);
22         ~Node();
23         /* return true = thread choice has already been explored */
24         bool has_been_explored(thread_id_t tid);
25         /* return true = backtrack set is empty */
26         bool backtrack_empty();
27         void explore_child(ModelAction *act);
28         /* return false = thread was already in backtrack */
29         bool set_backtrack(thread_id_t id);
30         thread_id_t get_next_backtrack();
31         bool is_enabled(Thread *t);
32         ModelAction * get_action() { return action; }
33
34         void add_read_from(ModelAction *act);
35
36         void print();
37
38         MEMALLOC
39 private:
40         void explore(thread_id_t tid);
41
42         ModelAction *action;
43         int num_threads;
44         std::vector< bool, MyAlloc<bool> > explored_children;
45         std::vector< bool, MyAlloc<bool> > backtrack;
46         int numBacktracks;
47
48         /** The set of ModelActions that this the action at this Node may read
49          *  from. Only meaningful if this Node represents a 'read' action. */
50         action_set_t may_read_from;
51 };
52
53 typedef std::list<class Node *, MyAlloc< class Node * > > node_list_t;
54
55 class NodeStack {
56 public:
57         NodeStack();
58         ~NodeStack();
59         ModelAction * explore_action(ModelAction *act);
60         Node * get_head();
61         Node * get_next();
62         void reset_execution();
63
64         int get_total_nodes() { return total_nodes; }
65
66         void print();
67
68         MEMALLOC
69 private:
70         node_list_t node_list;
71         node_list_t::iterator iter;
72
73         int total_nodes;
74 };
75
76 #endif /* __NODESTACK_H__ */