nodestack: don't perform linear search to check if backtrack is empty
[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         int numBacktracks;
42 };
43
44 typedef std::list<class Node *, MyAlloc< class Node * > > node_list_t;
45
46 class NodeStack {
47 public:
48         NodeStack();
49         ~NodeStack();
50         ModelAction * explore_action(ModelAction *act);
51         Node * get_head();
52         Node * get_next();
53         void reset_execution();
54
55         int get_total_nodes() { return total_nodes; }
56
57         void print();
58
59         MEMALLOC
60 private:
61         node_list_t node_list;
62         node_list_t::iterator iter;
63
64         int total_nodes;
65 };
66
67 #endif /* __NODESTACK_H__ */