Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use C++ ctor/new/delete for Pair
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 8 Mar 2016 10:59:09 +0000 (11:59 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 8 Mar 2016 12:32:15 +0000 (13:32 +0100)
src/mc/mc_global.cpp
src/mc/mc_liveness.cpp
src/mc/mc_liveness.h
src/mc/mc_pair.cpp [deleted file]
tools/cmake/DefinePackages.cmake

index 92e863c..898da3f 100644 (file)
@@ -436,7 +436,7 @@ void dump_stack_liveness(xbt_fifo_t stack)
 {
   simgrid::mc::Pair* pair;
   while ((pair = (simgrid::mc::Pair*) xbt_fifo_pop(stack)) != nullptr)
-    simgrid::mc::pair_delete(pair);
+    delete pair;
 }
 
 }
index 380c4c8..670f11c 100644 (file)
@@ -40,6 +40,20 @@ xbt_parmap_t parmap;
 
 /********* Static functions *********/
 
+namespace simgrid {
+namespace mc {
+
+Pair::Pair() : num(++mc_stats->expanded_pairs),
+  visited_pair_removed(_sg_mc_visited > 0 ? 0 : 1)
+{}
+
+Pair::~Pair() {
+  this->automaton_state = nullptr;
+  if (this->visited_pair_removed)
+    MC_state_delete(this->graph_state, 1);
+  xbt_dynar_free(&(this->atomic_propositions));
+}
+
 static xbt_dynar_t get_atomic_propositions_values()
 {
   unsigned int cursor = 0;
@@ -180,7 +194,7 @@ static void MC_pre_modelcheck_liveness(void)
   xbt_dynar_foreach(simgrid::mc::property_automaton->states, cursor, automaton_state) {
     if (automaton_state->type == -1) {  /* Initial automaton state */
 
-      initial_pair = simgrid::mc::pair_new();
+      initial_pair = new Pair();
       initial_pair->automaton_state = automaton_state;
       initial_pair->graph_state = MC_state_new();
       initial_pair->atomic_propositions = get_atomic_propositions_values();
@@ -302,7 +316,7 @@ static int MC_modelcheck_liveness_main(void)
            transition_succ = (xbt_automaton_transition_t)xbt_dynar_get_as(current_pair->automaton_state->out, cursor, xbt_automaton_transition_t);
            res = MC_automaton_evaluate_label(transition_succ->label, prop_values);
            if (res == 1 || res == 2) { /* 1 = True transition (always enabled), 2 = enabled transition according to atomic prop values */
-              next_pair = simgrid::mc::pair_new();
+              next_pair = new Pair();
               next_pair->graph_state = MC_state_new();
               next_pair->automaton_state = transition_succ->dst;
               next_pair->atomic_propositions = get_atomic_propositions_values();
@@ -350,7 +364,7 @@ static int MC_modelcheck_liveness_main(void)
           XBT_DEBUG("Delete pair %d at depth %d", current_pair->num, current_pair->depth);
           if (current_pair->automaton_state->type == 1) 
             remove_acceptance_pair(current_pair->num);
-          simgrid::mc::pair_delete(current_pair);
+          delete current_pair;
         }
       }
 
@@ -363,9 +377,6 @@ static int MC_modelcheck_liveness_main(void)
   return SIMGRID_MC_EXIT_SUCCESS;
 }
 
-namespace simgrid {
-namespace mc {
-
 int modelcheck_liveness(void)
 {
   if (mc_reduce_kind == e_mc_reduce_unset)
index c5d2acc..b75d935 100644 (file)
@@ -26,15 +26,21 @@ namespace mc {
 extern XBT_PRIVATE xbt_automaton_t property_automaton;
 
 struct XBT_PRIVATE Pair {
-  int num;
-  int search_cycle;
-  mc_state_t graph_state; /* System state included */
-  xbt_automaton_state_t automaton_state;
-  xbt_dynar_t atomic_propositions;
-  int requests;
-  int depth;
-  int exploration_started;
-  int visited_pair_removed;
+  int num = 0;
+  int search_cycle = 0;
+  mc_state_t graph_state = nullptr; /* System state included */
+  xbt_automaton_state_t automaton_state = nullptr;
+  xbt_dynar_t atomic_propositions = nullptr;
+  int requests = 0;
+  int depth = 0;
+  int exploration_started = 0;
+  int visited_pair_removed = 0;
+
+  Pair();
+  ~Pair();
+
+  Pair(Pair const&) = delete;
+  Pair& operator=(Pair const&) = delete;
 };
 
 struct XBT_PRIVATE VisitedPair {
@@ -50,8 +56,6 @@ struct XBT_PRIVATE VisitedPair {
   int visited_removed;
 };
 
-XBT_PRIVATE simgrid::mc::Pair* pair_new(void);
-XBT_PRIVATE void pair_delete(simgrid::mc::Pair*);
 XBT_PRIVATE simgrid::mc::VisitedPair* visited_pair_new(int pair_num, xbt_automaton_state_t automaton_state, xbt_dynar_t atomic_propositions, mc_state_t graph_state);
 XBT_PRIVATE void visited_pair_delete(simgrid::mc::VisitedPair* p);
 
diff --git a/src/mc/mc_pair.cpp b/src/mc/mc_pair.cpp
deleted file mode 100644 (file)
index 345a8f2..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright (c) 2013-2015. The SimGrid Team.
- * All rights reserved.                                                     */
-
-/* This program is free software; you can redistribute it and/or modify it
- * under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include <xbt/dynar.h>
-#include <xbt/sysdep.h>
-
-#include "src/mc/mc_liveness.h"
-#include "src/mc/mc_private.h"
-
-namespace simgrid {
-namespace mc {
-
-simgrid::mc::Pair* pair_new()
-{
-  simgrid::mc::Pair* p = nullptr;
-  p = xbt_new0(simgrid::mc::Pair, 1);
-  p->num = ++mc_stats->expanded_pairs;
-  p->exploration_started = 0;
-  p->search_cycle = 0;
-  p->visited_pair_removed = _sg_mc_visited > 0 ? 0 : 1;
-  return p;
-}
-
-void pair_delete(simgrid::mc::Pair* p)
-{
-  p->automaton_state = nullptr;
-  if(p->visited_pair_removed)
-    MC_state_delete(p->graph_state, 1);
-  xbt_dynar_free(&(p->atomic_propositions));
-  xbt_free(p);
-  p = nullptr;
-}
-
-}
-}
\ No newline at end of file
index fc48a0a..f7a60cf 100644 (file)
@@ -598,7 +598,6 @@ set(MC_SRC
   src/mc/mc_record.cpp
   src/mc/mc_member.cpp
   src/mc/mc_memory.cpp
-  src/mc/mc_pair.cpp
   src/mc/mc_private.h
   src/mc/mc_request.h
   src/mc/mc_request.cpp