more comments
[model-checker.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 <cstddef>
11 #include "threads.h"
12 #include "mymemory.h"
13
14 class ModelAction;
15
16 class Node {
17 public:
18         Node(ModelAction *act = NULL, int nthreads = 1);
19         ~Node();
20         /* return true = thread choice has already been explored */
21         bool has_been_explored(thread_id_t tid);
22         /* return true = backtrack set is empty */
23         bool backtrack_empty();
24         void explore_child(ModelAction *act);
25         /* return false = thread was already in backtrack */
26         bool set_backtrack(thread_id_t id);
27         thread_id_t get_next_backtrack();
28         bool is_enabled(Thread *t);
29         ModelAction * get_action() { return action; }
30
31         void print();
32
33         MEMALLOC
34 private:
35         void explore(thread_id_t tid);
36
37         ModelAction *action;
38         int num_threads;
39         std::vector< bool, MyAlloc<bool> > explored_children;
40         std::vector< bool, MyAlloc<bool> > backtrack;
41 };
42
43 typedef std::list<class Node *, MyAlloc< class Node * > > node_list_t;
44
45 class NodeStack {
46 public:
47         NodeStack();
48         ~NodeStack();
49         ModelAction * explore_action(ModelAction *act);
50         Node * get_head();
51         Node * get_next();
52         void reset_execution();
53
54         int get_total_nodes() { return total_nodes; }
55
56         void print();
57
58         MEMALLOC
59 private:
60         node_list_t node_list;
61         node_list_t::iterator iter;
62
63         int total_nodes;
64 };
65
66 #endif /* __NODESTACK_H__ */