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 act The ModelAction to associate with this Node. May be NULL.
24 * @param par The parent Node in the NodeStack. May be NULL if there is no
26 * @param nthreads The number of threads which exist at this point in the
29 Node::Node(ModelAction *act, Node *par, int nthreads) :
39 /** @brief Node desctructor */
47 /** Prints debugging info for the ModelAction associated with this Node */
48 void Node::print() const
53 NodeStack::NodeStack() :
61 NodeStack::~NodeStack()
63 for (unsigned int i = 0; i < node_list.size(); i++)
68 * @brief Register the model-checker object with this NodeStack
69 * @param exec The execution structure for the ModelChecker
71 void NodeStack::register_engine(const ModelExecution *exec)
73 this->execution = exec;
76 const struct model_params * NodeStack::get_params() const
78 return execution->get_params();
81 void NodeStack::print() const
83 model_print("............................................\n");
84 model_print("NodeStack printing node_list:\n");
85 for (unsigned int it = 0; it < node_list.size(); it++) {
86 if ((int)it == this->head_idx)
87 model_print("vvv following action is the current iterator vvv\n");
88 node_list[it]->print();
90 model_print("............................................\n");
93 /** Note: The is_enabled set contains what actions were enabled when
95 ModelAction * NodeStack::explore_action(ModelAction *act)
100 Node *head = get_head();
102 int next_threads = execution->get_num_threads();
103 if (act->get_type() == THREAD_CREATE || act->get_type() == PTHREAD_CREATE ) // may need to be changed
105 node_list.push_back(new Node(act, head, next_threads));
112 /** Reset the node stack. */
113 void NodeStack::full_reset()
115 for (unsigned int i = 0; i < node_list.size(); i++)
122 Node * NodeStack::get_head() const
124 if (node_list.empty() || head_idx < 0)
126 return node_list[head_idx];
129 Node * NodeStack::get_next() const
131 if (node_list.empty()) {
135 unsigned int it = head_idx + 1;
136 if (it == node_list.size()) {
140 return node_list[it];
143 void NodeStack::reset_execution()