2 * @brief Stack of operations for use in backtracking.
5 #ifndef __NODESTACK_H__
6 #define __NODESTACK_H__
13 #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 #define PROMISE_IGNORE 0 /**< This promise is inapplicable; ignore it */
28 #define PROMISE_UNFULFILLED 1 /**< This promise is applicable but unfulfilled */
29 #define PROMISE_FULFILLED 2 /**< This promise is applicable and fulfilled */
30 #define PROMISE_MASK 0xf
31 #define PROMISE_RMW 0x10
33 typedef int promise_t;
37 modelclock_t expiration;
40 struct fairness_info {
41 unsigned int enabled_count;
48 * @brief A single node in a NodeStack
50 * Represents a single node in the NodeStack. Each Node is associated with up
51 * to one action and up to one parent node. A node holds information
52 * regarding the last action performed (the "associated action"), the thread
53 * choices that have been explored (explored_children) and should be explored
54 * (backtrack), and the actions that the last action may read from.
58 Node(ModelAction *act, Node *par, int nthreads, Node *prevfairness);
60 /* return true = thread choice has already been explored */
61 bool has_been_explored(thread_id_t tid) const;
62 /* return true = backtrack set is empty */
63 bool backtrack_empty() const;
65 void explore_child(ModelAction *act, enabled_type_t *is_enabled);
66 /* return false = thread was already in backtrack */
67 bool set_backtrack(thread_id_t id);
68 thread_id_t get_next_backtrack();
69 bool is_enabled(Thread *t) const;
70 bool is_enabled(thread_id_t tid) const;
71 enabled_type_t enabled_status(thread_id_t tid) const;
73 ModelAction * get_action() const { return action; }
74 bool has_priority(thread_id_t tid) const;
75 int get_num_threads() const { return num_threads; }
76 /** @return the parent Node to this Node; that is, the action that
77 * occurred previously in the stack. */
78 Node * get_parent() const { return parent; }
80 bool add_future_value(uint64_t value, modelclock_t expiration);
81 uint64_t get_future_value() const;
82 modelclock_t get_future_value_expiration() const;
83 bool increment_future_value();
84 bool future_value_empty() const;
86 void add_read_from(const ModelAction *act);
87 const ModelAction * get_read_from() const;
88 bool increment_read_from();
89 bool read_from_empty() const;
90 int get_read_from_size() const;
91 const ModelAction * get_read_from_at(int i) const;
93 void set_promise(unsigned int i, bool is_rmw);
94 bool get_promise(unsigned int i) const;
95 bool increment_promise();
96 bool promise_empty() const;
97 enabled_type_t *get_enabled_array() {return enabled_array;}
99 void set_misc_max(int i);
100 int get_misc() const;
101 bool increment_misc();
102 bool misc_empty() const;
104 void add_relseq_break(const ModelAction *write);
105 const ModelAction * get_relseq_break() const;
106 bool increment_relseq_break();
107 bool relseq_break_empty() const;
110 void print_may_read_from();
114 void explore(thread_id_t tid);
116 ModelAction * const action;
118 const int num_threads;
119 std::vector< bool, ModelAlloc<bool> > explored_children;
120 std::vector< bool, ModelAlloc<bool> > backtrack;
121 std::vector< struct fairness_info, ModelAlloc< struct fairness_info> > fairness;
123 enabled_type_t *enabled_array;
125 /** The set of ModelActions that this the action at this Node may read
126 * from. Only meaningful if this Node represents a 'read' action. */
127 std::vector< const ModelAction *, ModelAlloc< const ModelAction * > > may_read_from;
129 unsigned int read_from_index;
131 std::vector< struct future_value, ModelAlloc<struct future_value> > future_values;
132 std::vector< promise_t, ModelAlloc<promise_t> > promises;
135 std::vector< const ModelAction *, ModelAlloc<const ModelAction *> > relseq_break_writes;
136 int relseq_break_index;
142 typedef std::vector< Node *, ModelAlloc< Node * > > node_list_t;
145 * @brief A stack of nodes
147 * Holds a Node linked-list that can be used for holding backtracking,
148 * may-read-from, and replay information. It is used primarily as a
149 * stack-like structure, in that backtracking points and replay nodes are
150 * only removed from the top (most recent).
156 ModelAction * explore_action(ModelAction *act, enabled_type_t * is_enabled);
157 Node * get_head() const;
158 Node * get_next() const;
159 void reset_execution();
160 void pop_restofstack(int numAhead);
161 int get_total_nodes() { return total_nodes; }
167 node_list_t node_list;
170 * @brief the index position of the current head Node
172 * This index is relative to node_list. The index should point to the
173 * current head Node. It is negative when the list is empty.
180 #endif /* __NODESTACK_H__ */