2 * @brief Stack of operations for use in backtracking.
5 #ifndef __NODESTACK_H__
6 #define __NODESTACK_H__
16 typedef std::vector< const ModelAction *, MyAlloc< const ModelAction * > > readfrom_set_t;
17 typedef std::vector< uint64_t, MyAlloc< uint64_t > > futurevalues_t;
20 * @brief A single node in a NodeStack
22 * Represents a single node in the NodeStack. Each Node is associated with up
23 * to one action and up to one parent node. A node holds information
24 * regarding the last action performed (the "associated action"), the thread
25 * choices that have been explored (explored_children) and should be explored
26 * (backtrack), and the actions that the last action may read from.
30 Node(ModelAction *act = NULL, Node *par = NULL, int nthreads = 1);
32 /* return true = thread choice has already been explored */
33 bool has_been_explored(thread_id_t tid);
34 /* return true = backtrack set is empty */
35 bool backtrack_empty();
36 bool readsfrom_empty();
37 bool futurevalues_empty();
38 void explore_child(ModelAction *act);
39 /* return false = thread was already in backtrack */
40 bool set_backtrack(thread_id_t id);
41 thread_id_t get_next_backtrack();
42 bool is_enabled(Thread *t);
43 ModelAction * get_action() { return action; }
45 /** @return the parent Node to this Node; that is, the action that
46 * occurred previously in the stack. */
47 Node * get_parent() const { return parent; }
49 void add_future_value(uint64_t value);
50 void add_read_from(const ModelAction *act);
51 const ModelAction * get_read_from();
52 uint64_t get_future_value();
53 bool increment_read_from();
54 bool increment_future_values();
57 void print_may_read_from();
61 void explore(thread_id_t tid);
66 std::vector< bool, MyAlloc<bool> > explored_children;
67 std::vector< bool, MyAlloc<bool> > backtrack;
70 /** The set of ModelActions that this the action at this Node may read
71 * from. Only meaningful if this Node represents a 'read' action. */
72 readfrom_set_t may_read_from;
73 unsigned int read_from_index;
75 futurevalues_t future_values;
76 unsigned int future_index;
79 typedef std::list< Node *, MyAlloc< Node * > > node_list_t;
82 * @brief A stack of nodes
84 * Holds a Node linked-list that can be used for holding backtracking,
85 * may-read-from, and replay information. It is used primarily as a
86 * stack-like structure, in that backtracking points and replay nodes are
87 * only removed from the top (most recent).
93 ModelAction * explore_action(ModelAction *act);
96 void reset_execution();
97 void pop_restofstack(int numAhead);
98 int get_total_nodes() { return total_nodes; }
104 node_list_t node_list;
105 node_list_t::iterator iter;
110 #endif /* __NODESTACK_H__ */