2 * @brief Stack of operations for use in backtracking.
5 #ifndef __NODESTACK_H__
6 #define __NODESTACK_H__
14 #include "modeltypes.h"
20 * A flag used for the promise counting/combination problem within a node,
21 * denoting whether a particular Promise is
22 * <ol><li>@b applicable: can be satisfied by this Node's ModelAction and</li>
23 * <li>@b fulfilled: satisfied by this Node's ModelAction under the current
24 * configuration.</li></ol>
27 PROMISE_IGNORE = 0, /**< This promise is inapplicable; ignore it */
28 PROMISE_UNFULFILLED, /**< This promise is applicable but unfulfilled */
29 PROMISE_FULFILLED /**< This promise is applicable and fulfilled */
34 modelclock_t expiration;
37 struct fairness_info {
38 unsigned int enabled_count;
45 * @brief A single node in a NodeStack
47 * Represents a single node in the NodeStack. Each Node is associated with up
48 * to one action and up to one parent node. A node holds information
49 * regarding the last action performed (the "associated action"), the thread
50 * choices that have been explored (explored_children) and should be explored
51 * (backtrack), and the actions that the last action may read from.
55 Node(ModelAction *act = NULL, Node *par = NULL, int nthreads = 1, Node *prevfairness = NULL);
57 /* return true = thread choice has already been explored */
58 bool has_been_explored(thread_id_t tid);
59 /* return true = backtrack set is empty */
60 bool backtrack_empty();
62 void explore_child(ModelAction *act, bool * is_enabled);
63 /* return false = thread was already in backtrack */
64 bool set_backtrack(thread_id_t id);
65 thread_id_t get_next_backtrack();
66 bool is_enabled(Thread *t);
67 bool is_enabled(thread_id_t tid);
68 ModelAction * get_action() { return action; }
69 bool has_priority(thread_id_t tid);
70 int get_num_threads() {return num_threads;}
71 /** @return the parent Node to this Node; that is, the action that
72 * occurred previously in the stack. */
73 Node * get_parent() const { return parent; }
75 bool add_future_value(uint64_t value, modelclock_t expiration);
76 uint64_t get_future_value();
77 modelclock_t get_future_value_expiration();
78 bool increment_future_value();
79 bool future_value_empty();
81 void add_read_from(const ModelAction *act);
82 const ModelAction * get_read_from();
83 bool increment_read_from();
84 bool read_from_empty();
85 int get_read_from_size();
86 const ModelAction * get_read_from_at(int i);
88 void set_promise(unsigned int i);
89 bool get_promise(unsigned int i);
90 bool increment_promise();
94 void print_may_read_from();
98 void explore(thread_id_t tid);
103 std::vector< bool, ModelAlloc<bool> > explored_children;
104 std::vector< bool, ModelAlloc<bool> > backtrack;
105 std::vector< struct fairness_info, ModelAlloc< struct fairness_info> > fairness;
109 /** The set of ModelActions that this the action at this Node may read
110 * from. Only meaningful if this Node represents a 'read' action. */
111 std::vector< const ModelAction *, ModelAlloc< const ModelAction * > > may_read_from;
113 unsigned int read_from_index;
115 std::vector< struct future_value, ModelAlloc<struct future_value> > future_values;
116 std::vector< promise_t, ModelAlloc<promise_t> > promises;
120 typedef std::vector< Node *, ModelAlloc< Node * > > node_list_t;
123 * @brief A stack of nodes
125 * Holds a Node linked-list that can be used for holding backtracking,
126 * may-read-from, and replay information. It is used primarily as a
127 * stack-like structure, in that backtracking points and replay nodes are
128 * only removed from the top (most recent).
134 ModelAction * explore_action(ModelAction *act, bool * is_enabled);
137 void reset_execution();
138 void pop_restofstack(int numAhead);
139 int get_total_nodes() { return total_nodes; }
145 node_list_t node_list;
151 #endif /* __NODESTACK_H__ */