nodestack: destroy Nodes properly in ~NodeStack()
[model-checker.git] / nodestack.cc
index b33d24739ca89399ffb363c1ba3bdecd61ca6dc2..6b1d4ef9c86929fdd14d14172149abaacec96133 100644 (file)
@@ -4,6 +4,7 @@
 #include "action.h"
 #include "common.h"
 #include "model.h"
+#include "threads.h"
 
 /**
  * @brief Node constructor
@@ -273,6 +274,11 @@ bool Node::is_enabled(thread_id_t tid)
        return thread_id < num_threads && enabled_array[thread_id];
 }
 
+bool Node::has_priority(thread_id_t tid)
+{
+       return fairness[id_to_int(tid)].priority;
+}
+
 /**
  * Add an action to the may_read_from set.
  * @param act is the action to add
@@ -325,8 +331,11 @@ const ModelAction * Node::get_read_from() {
 bool Node::increment_read_from() {
        DBG();
        promises.clear();
-       read_from_index++;
-       return (read_from_index < may_read_from.size());
+       if (read_from_index < may_read_from.size()) {
+               read_from_index++;
+               return read_from_index < may_read_from.size();
+       }
+       return false;
 }
 
 /**
@@ -336,8 +345,11 @@ bool Node::increment_read_from() {
 bool Node::increment_future_value() {
        DBG();
        promises.clear();
-       future_index++;
-       return (future_index < (int)future_values.size());
+       if (future_index < ((int)future_values.size())) {
+               future_index++;
+               return (future_index < ((int)future_values.size()));
+       }
+       return false;
 }
 
 void Node::explore(thread_id_t tid)
@@ -350,16 +362,18 @@ void Node::explore(thread_id_t tid)
        explored_children[i] = true;
 }
 
-NodeStack::NodeStack()
-       : total_nodes(0)
+NodeStack::NodeStack() :
+       node_list(1, new Node()),
+       iter(0),
+       total_nodes(0)
 {
-       node_list.push_back(new Node());
        total_nodes++;
-       iter = 0;
 }
 
 NodeStack::~NodeStack()
 {
+       for (unsigned int i = 0; i < node_list.size(); i++)
+               delete node_list[i];
 }
 
 void NodeStack::print()
@@ -412,6 +426,8 @@ void NodeStack::pop_restofstack(int numAhead)
 {
        /* Diverging from previous execution; clear out remainder of list */
        unsigned int it=iter+numAhead;
+       for(unsigned int i=it;i<node_list.size();i++)
+               delete node_list[i];
        node_list.resize(it);
 }