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;
19 * @brief A single node in a NodeStack
21 * Represents a single node in the NodeStack. Each Node is associated with up
22 * to one action and up to one parent node. A node holds information
23 * regarding the last action performed (the "associated action"), the thread
24 * choices that have been explored (explored_children) and should be explored
25 * (backtrack), and the actions that the last action may read from.
29 Node(ModelAction *act = NULL, Node *par = NULL, int nthreads = 1);
31 /* return true = thread choice has already been explored */
32 bool has_been_explored(thread_id_t tid);
33 /* return true = backtrack set is empty */
34 bool backtrack_empty();
35 bool readsfrom_empty();
36 void explore_child(ModelAction *act);
37 /* return false = thread was already in backtrack */
38 bool set_backtrack(thread_id_t id);
39 thread_id_t get_next_backtrack();
40 bool is_enabled(Thread *t);
41 ModelAction * get_action() { return action; }
43 /** @return the parent Node to this Node; that is, the action that
44 * occurred previously in the stack. */
45 Node * get_parent() const { return parent; }
47 void add_read_from(const ModelAction *act);
48 const ModelAction * get_read_from();
49 bool increment_read_from();
52 void print_may_read_from();
56 void explore(thread_id_t tid);
61 std::vector< bool, MyAlloc<bool> > explored_children;
62 std::vector< bool, MyAlloc<bool> > backtrack;
65 /** The set of ModelActions that this the action at this Node may read
66 * from. Only meaningful if this Node represents a 'read' action. */
67 readfrom_set_t may_read_from;
68 unsigned int read_from_index;
71 typedef std::list< Node *, MyAlloc< Node * > > node_list_t;
74 * @brief A stack of nodes
76 * Holds a Node linked-list that can be used for holding backtracking,
77 * may-read-from, and replay information. It is used primarily as a
78 * stack-like structure, in that backtracking points and replay nodes are
79 * only removed from the top (most recent).
85 ModelAction * explore_action(ModelAction *act);
88 void reset_execution();
89 void pop_restofstack(int numAhead);
90 int get_total_nodes() { return total_nodes; }
96 node_list_t node_list;
97 node_list_t::iterator iter;
102 #endif /* __NODESTACK_H__ */