nodestack, model: use uniform spacing, style
[model-checker.git] / model.cc
index 25f85d0ee4403ebb1b6ef00531cf872bbdd29892..531ef7e078695ce84811e276ad7f1347a94dbb71 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -34,7 +34,7 @@ ModelChecker::ModelChecker(struct model_params params) :
        thrd_last_action(new std::vector<ModelAction *>(1)),
        node_stack(new NodeStack()),
        next_backtrack(NULL),
-       cyclegraph(new CycleGraph()),
+       mo_graph(new CycleGraph()),
        failed_promise(false)
 {
 }
@@ -49,10 +49,15 @@ ModelChecker::~ModelChecker()
        delete obj_thrd_map;
        delete obj_map;
        delete action_trace;
+
+       for (unsigned int i = 0; i < promises->size(); i++)
+               delete (*promises)[i];
+       delete promises;
+
        delete thrd_last_action;
        delete node_stack;
        delete scheduler;
-       delete cyclegraph;
+       delete mo_graph;
 }
 
 /**
@@ -360,7 +365,7 @@ void ModelChecker::check_current_action(void)
 
 /** @returns whether the current partial trace is feasible. */
 bool ModelChecker::isfeasible() {
-       return !cyclegraph->checkForCycles() && !failed_promise;
+       return !mo_graph->checkForCycles() && !failed_promise;
 }
 
 /** Returns whether the current completed trace is feasible. */
@@ -374,12 +379,12 @@ ModelAction * ModelChecker::process_rmw(ModelAction * act) {
        ModelAction *lastread = get_last_action(tid);
        lastread->process_rmw(act);
        if (act->is_rmw())
-               cyclegraph->addRMWEdge(lastread, lastread->get_reads_from());
+               mo_graph->addRMWEdge(lastread->get_reads_from(), lastread);
        return lastread;
 }
 
 /**
- * Updates the cyclegraph with the constraints imposed from the current read.
+ * Updates the mo_graph with the constraints imposed from the current read.
  * @param curr The current action. Must be a read.
  * @param rf The action that curr reads from. Must be a write.
  */
@@ -401,9 +406,9 @@ void ModelChecker::r_modification_order(ModelAction * curr, const ModelAction *r
                                if (act->is_read()) {
                                        const ModelAction * prevreadfrom = act->get_reads_from();
                                        if (prevreadfrom != NULL && rf != prevreadfrom)
-                                               cyclegraph->addEdge(rf, prevreadfrom);
+                                               mo_graph->addEdge(prevreadfrom, rf);
                                } else if (rf != act) {
-                                       cyclegraph->addEdge(rf, act);
+                                       mo_graph->addEdge(act, rf);
                                }
                                break;
                        }
@@ -411,8 +416,7 @@ void ModelChecker::r_modification_order(ModelAction * curr, const ModelAction *r
        }
 }
 
-/** Updates the cyclegraph with the constraints imposed from the
- *  current read. */
+/** Updates the mo_graph with the constraints imposed from the current read. */
 void ModelChecker::post_r_modification_order(ModelAction * curr, const ModelAction *rf) {
        std::vector<action_list_t> *thrd_lists = obj_thrd_map->get_safe_ptr(curr->get_location());
        unsigned int i;
@@ -439,9 +443,9 @@ void ModelChecker::post_r_modification_order(ModelAction * curr, const ModelActi
                        if (lastact->is_read()) {
                                const ModelAction * postreadfrom = lastact->get_reads_from();
                                if (postreadfrom != NULL&&rf != postreadfrom)
-                                       cyclegraph->addEdge(postreadfrom, rf);
+                                       mo_graph->addEdge(rf, postreadfrom);
                        } else if (rf != lastact) {
-                               cyclegraph->addEdge(lastact, rf);
+                               mo_graph->addEdge(rf, lastact);
                        }
                        break;
                }
@@ -449,7 +453,7 @@ void ModelChecker::post_r_modification_order(ModelAction * curr, const ModelActi
 }
 
 /**
- * Updates the cyclegraph with the constraints imposed from the current write.
+ * Updates the mo_graph with the constraints imposed from the current write.
  * @param curr The current action. Must be a write.
  */
 void ModelChecker::w_modification_order(ModelAction * curr) {
@@ -462,7 +466,7 @@ void ModelChecker::w_modification_order(ModelAction * curr) {
                         so we are initialized. */
                ModelAction * last_seq_cst = get_last_seq_cst(curr->get_location());
                if (last_seq_cst != NULL)
-                       cyclegraph->addEdge(curr, last_seq_cst);
+                       mo_graph->addEdge(last_seq_cst, curr);
        }
 
        /* Iterate over all threads */
@@ -476,9 +480,9 @@ void ModelChecker::w_modification_order(ModelAction * curr) {
                        /* Include at most one act per-thread that "happens before" curr */
                        if (act->happens_before(curr)) {
                                if (act->is_read())
-                                       cyclegraph->addEdge(curr, act->get_reads_from());
+                                       mo_graph->addEdge(act->get_reads_from(), curr);
                                else
-                                       cyclegraph->addEdge(curr, act);
+                                       mo_graph->addEdge(act, curr);
                                break;
                        } else if (act->is_read() && !act->is_synchronizing(curr) &&
                                                     !act->same_thread(curr)) {
@@ -560,22 +564,22 @@ ModelAction * ModelChecker::get_parent_action(thread_id_t tid)
  * @param tid The thread whose clock vector we want
  * @return Desired clock vector
  */
-ClockVector * ModelChecker::get_cv(thread_id_t tid) {
+ClockVector * ModelChecker::get_cv(thread_id_t tid)
+{
        return get_parent_action(tid)->get_cv();
 }
 
-
 /** Resolve the given promises. */
-
-void ModelChecker::resolve_promises(ModelAction *write) {
-       for (unsigned int i = 0, promise_index = 0;promise_index<promises->size(); i++) {
-               Promise * promise = (*promises)[promise_index];
+void ModelChecker::resolve_promises(ModelAction *write)
+{
+       for (unsigned int i = 0, promise_index = 0; promise_index < promises->size(); i++) {
+               Promise *promise = (*promises)[promise_index];
                if (write->get_node()->get_promise(i)) {
-                       ModelAction * read = promise->get_action();
+                       ModelAction *read = promise->get_action();
                        read->read_from(write);
                        r_modification_order(read, write);
                        post_r_modification_order(read, write);
-                       promises->erase(promises->begin()+promise_index);
+                       promises->erase(promises->begin() + promise_index);
                } else
                        promise_index++;
        }
@@ -583,15 +587,15 @@ void ModelChecker::resolve_promises(ModelAction *write) {
 
 /** Compute the set of promises that could potentially be satisfied by
  *  this action. */
-
-void ModelChecker::compute_promises(ModelAction *curr) {
-       for (unsigned int i = 0;i<promises->size();i++) {
-               Promise * promise = (*promises)[i];
-               const ModelAction * act = promise->get_action();
-               if (!act->happens_before(curr)&&
-                               act->is_read()&&
-                               !act->is_synchronizing(curr)&&
-                               !act->same_thread(curr)&&
+void ModelChecker::compute_promises(ModelAction *curr)
+{
+       for (unsigned int i = 0; i < promises->size(); i++) {
+               Promise *promise = (*promises)[i];
+               const ModelAction *act = promise->get_action();
+               if (!act->happens_before(curr) &&
+                               act->is_read() &&
+                               !act->is_synchronizing(curr) &&
+                               !act->same_thread(curr) &&
                                promise->get_value() == curr->get_value()) {
                        curr->get_node()->set_promise(i);
                }
@@ -599,12 +603,12 @@ void ModelChecker::compute_promises(ModelAction *curr) {
 }
 
 /** Checks promises in response to change in ClockVector Threads. */
-
-void ModelChecker::check_promises(ClockVector *old_cv, ClockVector * merge_cv) {
-       for (unsigned int i = 0;i<promises->size();i++) {
-               Promise * promise = (*promises)[i];
-               const ModelAction * act = promise->get_action();
-               if ((old_cv == NULL||!old_cv->synchronized_since(act))&&
+void ModelChecker::check_promises(ClockVector *old_cv, ClockVector *merge_cv)
+{
+       for (unsigned int i = 0; i < promises->size(); i++) {
+               Promise *promise = (*promises)[i];
+               const ModelAction *act = promise->get_action();
+               if ((old_cv == NULL || !old_cv->synchronized_since(act)) &&
                                merge_cv->synchronized_since(act)) {
                        //This thread is no longer able to send values back to satisfy the promise
                        int num_synchronized_threads = promise->increment_threads();