From: Gabriel Corona Date: Tue, 8 Mar 2016 10:59:09 +0000 (+0100) Subject: [mc] Use C++ ctor/new/delete for Pair X-Git-Tag: v3_13~481 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/124b3dee9ed0b4342bc495061c2a5167a9fc6318?hp=7cdbe5b848fd1f600182c38fcd1b7268130dc9c9 [mc] Use C++ ctor/new/delete for Pair --- diff --git a/src/mc/mc_global.cpp b/src/mc/mc_global.cpp index 92e863cfc9..898da3f27b 100644 --- a/src/mc/mc_global.cpp +++ b/src/mc/mc_global.cpp @@ -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; } } diff --git a/src/mc/mc_liveness.cpp b/src/mc/mc_liveness.cpp index 380c4c8aff..670f11c8f9 100644 --- a/src/mc/mc_liveness.cpp +++ b/src/mc/mc_liveness.cpp @@ -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) diff --git a/src/mc/mc_liveness.h b/src/mc/mc_liveness.h index c5d2acc61a..b75d93552b 100644 --- a/src/mc/mc_liveness.h +++ b/src/mc/mc_liveness.h @@ -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 index 345a8f2553..0000000000 --- a/src/mc/mc_pair.cpp +++ /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 -#include - -#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 diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index fc48a0ac66..f7a60cf060 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -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