remove another field
[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 <cstddef>
9 #include <inttypes.h>
10
11 #include "mymemory.h"
12 #include "schedule.h"
13 #include "stl-model.h"
14
15 class ModelAction;
16 class Thread;
17
18 struct fairness_info {
19         unsigned int enabled_count;
20         unsigned int turns;
21         bool priority;
22 };
23
24
25 /**
26  * @brief A single node in a NodeStack
27  *
28  * Represents a single node in the NodeStack. Each Node is associated with up
29  * to one action and up to one parent node. A node holds information
30  * regarding the last action performed (the "associated action"), the thread
31  * choices that have been explored (explored_children) and should be explored
32  * (backtrack), and the actions that the last action may read from.
33  */
34 class Node {
35 public:
36         Node(ModelAction *act, Node *par,
37                         int nthreads);
38         ~Node();
39
40         bool is_enabled(Thread *t) const;
41         bool is_enabled(thread_id_t tid) const;
42
43         ModelAction * get_action() const { return action; }
44         void set_uninit_action(ModelAction *act) { uninit_action = act; }
45         ModelAction * get_uninit_action() const { return uninit_action; }
46
47         int get_num_threads() const { return num_threads; }
48         /** @return the parent Node to this Node; that is, the action that
49          * occurred previously in the stack. */
50         Node * get_parent() const { return parent; }
51
52
53
54         void print() const;
55
56         MEMALLOC
57 private:
58         ModelAction * const action;
59
60         /** @brief ATOMIC_UNINIT action which was created at this Node */
61         ModelAction *uninit_action;
62         Node * const parent;
63         const int num_threads;
64 };
65
66 typedef ModelVector<Node *> node_list_t;
67
68 /**
69  * @brief A stack of nodes
70  *
71  * Holds a Node linked-list that can be used for holding backtracking,
72  * may-read-from, and replay information. It is used primarily as a
73  * stack-like structure, in that backtracking points and replay nodes are
74  * only removed from the top (most recent).
75  */
76 class NodeStack {
77 public:
78         NodeStack();
79         ~NodeStack();
80
81         void register_engine(const ModelExecution *exec);
82
83         ModelAction * explore_action(ModelAction *act);
84         Node * get_head() const;
85         Node * get_next() const;
86         void reset_execution();
87         void full_reset();
88         int get_total_nodes() { return total_nodes; }
89
90         void print() const;
91
92         MEMALLOC
93 private:
94         node_list_t node_list;
95
96         const struct model_params * get_params() const;
97
98         /** @brief The model-checker execution object */
99         const ModelExecution *execution;
100
101         /**
102          * @brief the index position of the current head Node
103          *
104          * This index is relative to node_list. The index should point to the
105          * current head Node. It is negative when the list is empty.
106          */
107         int head_idx;
108
109         int total_nodes;
110 };
111
112 #endif /* __NODESTACK_H__ */