1 #define __STDC_FORMAT_MACROS
10 #include "threads-model.h"
11 #include "modeltypes.h"
12 #include "execution.h"
16 * @brief Node constructor
18 * Constructs a single Node for use in a NodeStack. Each Node is associated
19 * with exactly one ModelAction (exception: the first Node should be created
20 * as an empty stub, to represent the first thread "choice") and up to one
23 * @param params The model-checker parameters
24 * @param act The ModelAction to associate with this Node. May be NULL.
25 * @param par The parent Node in the NodeStack. May be NULL if there is no
27 * @param nthreads The number of threads which exist at this point in the
30 Node::Node(const struct model_params *params, ModelAction *act, Node *par,
42 /** @brief Node desctructor */
50 /** Prints debugging info for the ModelAction associated with this Node */
51 void Node::print() const
56 NodeStack::NodeStack() :
64 NodeStack::~NodeStack()
66 for (unsigned int i = 0; i < node_list.size(); i++)
71 * @brief Register the model-checker object with this NodeStack
72 * @param exec The execution structure for the ModelChecker
74 void NodeStack::register_engine(const ModelExecution *exec)
76 this->execution = exec;
79 const struct model_params * NodeStack::get_params() const
81 return execution->get_params();
84 void NodeStack::print() const
86 model_print("............................................\n");
87 model_print("NodeStack printing node_list:\n");
88 for (unsigned int it = 0; it < node_list.size(); it++) {
89 if ((int)it == this->head_idx)
90 model_print("vvv following action is the current iterator vvv\n");
91 node_list[it]->print();
93 model_print("............................................\n");
96 /** Note: The is_enabled set contains what actions were enabled when
98 ModelAction * NodeStack::explore_action(ModelAction *act, enabled_type_t *is_enabled)
103 Node *head = get_head();
105 int next_threads = execution->get_num_threads();
106 if (act->get_type() == THREAD_CREATE || act->get_type() == PTHREAD_CREATE ) // may need to be changed
108 node_list.push_back(new Node(get_params(), act, head, next_threads));
115 /** Reset the node stack. */
116 void NodeStack::full_reset()
118 for (unsigned int i = 0; i < node_list.size(); i++)
125 Node * NodeStack::get_head() const
127 if (node_list.empty() || head_idx < 0)
129 return node_list[head_idx];
132 Node * NodeStack::get_next() const
134 if (node_list.empty()) {
138 unsigned int it = head_idx + 1;
139 if (it == node_list.size()) {
143 return node_list[it];
146 void NodeStack::reset_execution()