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;
18 typedef std::vector< uint32_t, MyAlloc< uint32_t > > promises_t;
21 * @brief A single node in a NodeStack
23 * Represents a single node in the NodeStack. Each Node is associated with up
24 * to one action and up to one parent node. A node holds information
25 * regarding the last action performed (the "associated action"), the thread
26 * choices that have been explored (explored_children) and should be explored
27 * (backtrack), and the actions that the last action may read from.
31 Node(ModelAction *act = NULL, Node *par = NULL, int nthreads = 1);
33 /* return true = thread choice has already been explored */
34 bool has_been_explored(thread_id_t tid);
35 /* return true = backtrack set is empty */
36 bool backtrack_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 bool add_future_value(uint64_t value);
50 uint64_t get_future_value();
51 bool increment_future_value();
52 bool future_value_empty();
54 void add_read_from(const ModelAction *act);
55 const ModelAction * get_read_from();
56 bool increment_read_from();
57 bool read_from_empty();
59 void set_promise(uint32_t i);
60 bool get_promise(uint32_t i);
61 bool increment_promise();
65 void print_may_read_from();
69 void explore(thread_id_t tid);
74 std::vector< bool, MyAlloc<bool> > explored_children;
75 std::vector< bool, MyAlloc<bool> > backtrack;
78 /** The set of ModelActions that this the action at this Node may read
79 * from. Only meaningful if this Node represents a 'read' action. */
80 readfrom_set_t may_read_from;
81 unsigned int read_from_index;
83 futurevalues_t future_values;
85 unsigned int future_index;
88 typedef std::list< Node *, MyAlloc< Node * > > node_list_t;
91 * @brief A stack of nodes
93 * Holds a Node linked-list that can be used for holding backtracking,
94 * may-read-from, and replay information. It is used primarily as a
95 * stack-like structure, in that backtracking points and replay nodes are
96 * only removed from the top (most recent).
102 ModelAction * explore_action(ModelAction *act);
105 void reset_execution();
106 void pop_restofstack(int numAhead);
107 int get_total_nodes() { return total_nodes; }
113 node_list_t node_list;
114 node_list_t::iterator iter;
119 #endif /* __NODESTACK_H__ */