Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Make Snapshot::snapshot_regions a std::vector
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 8 Jun 2015 10:34:56 +0000 (12:34 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 08:20:44 +0000 (10:20 +0200)
src/mc/mc_checkpoint.cpp
src/mc/mc_compare.cpp
src/mc/mc_diff.cpp
src/mc/mc_snapshot.cpp
src/mc/mc_snapshot.h

index d420aa9..cda2505 100644 (file)
@@ -165,17 +165,16 @@ static void MC_snapshot_add_region(int index, mc_snapshot_t snapshot,
 
   region.object_info(object_info);
   snapshot->snapshot_regions[index]
-    = new simgrid::mc::RegionSnapshot(std::move(region));
+    = std::unique_ptr<simgrid::mc::RegionSnapshot>(
+      new simgrid::mc::RegionSnapshot(std::move(region)));
   return;
 }
 
 static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot)
 {
   const size_t n = process->object_infos_size;
-  snapshot->snapshot_regions_count = n + 1;
-  snapshot->snapshot_regions = xbt_new0(mc_mem_region_t, n + 1);
-
-  for (size_t i = 0; i!=n; ++i) {
+  snapshot->snapshot_regions.resize(n + 1);
+  for (size_t i = 0; i != n; ++i) {
     mc_object_info_t object_info = process->object_infos[i];
     MC_snapshot_add_region(i, snapshot, simgrid::mc::RegionType::Data, object_info,
       object_info->start_rw, object_info->start_rw,
@@ -651,11 +650,10 @@ mc_snapshot_t MC_take_snapshot(int num_state)
 static inline
 void MC_restore_snapshot_regions(mc_snapshot_t snapshot)
 {
-  const size_t n = snapshot->snapshot_regions_count;
-  for (size_t i = 0; i < n; i++) {
+  for(std::unique_ptr<s_mc_mem_region_t> const& region : snapshot->snapshot_regions) {
     // For privatized, variables we decided it was not necessary to take the snapshot:
-    if (snapshot->snapshot_regions[i])
-      MC_region_restore(snapshot->snapshot_regions[i]);
+    if (region)
+      MC_region_restore(region.get());
   }
 
 #ifdef HAVE_SMPI
index d43907a..56b01f6 100644 (file)
@@ -574,15 +574,15 @@ int snapshot_compare(void *state1, void *state2)
     cursor++;
   }
 
-  size_t regions_count = s1->snapshot_regions_count;
+  size_t regions_count = s1->snapshot_regions.size();
   // TODO, raise a difference instead?
-  xbt_assert(regions_count == s2->snapshot_regions_count);
+  xbt_assert(regions_count == s2->snapshot_regions.size());
 
   mc_comp_times->global_variables_comparison_time = 0;
 
   for (size_t k = 0; k != regions_count; ++k) {
-    mc_mem_region_t region1 = s1->snapshot_regions[k];
-    mc_mem_region_t region2 = s2->snapshot_regions[k];
+    mc_mem_region_t region1 = s1->snapshot_regions[k].get();
+    mc_mem_region_t region2 = s2->snapshot_regions[k].get();
 
     // Preconditions:
     if (region1->region_type() != simgrid::mc::RegionType::Data)
index 35e8779..06b1141 100644 (file)
@@ -419,9 +419,9 @@ void reset_heap_information()
 static inline
 mc_mem_region_t MC_get_heap_region(mc_snapshot_t snapshot)
 {
-  size_t n = snapshot->snapshot_regions_count;
+  size_t n = snapshot->snapshot_regions.size();
   for (size_t i=0; i!=n; ++i) {
-    mc_mem_region_t region = snapshot->snapshot_regions[i];
+    mc_mem_region_t region = snapshot->snapshot_regions[i].get();
     if (region->region_type() == simgrid::mc::RegionType::Heap)
       return region;
   }
index 54f07ba..0fdb7a1 100644 (file)
@@ -26,9 +26,9 @@ extern "C" {
 mc_mem_region_t mc_get_snapshot_region(
   const void* addr, const s_mc_snapshot_t* snapshot, int process_index)
 {
-  size_t n = snapshot->snapshot_regions_count;
+  size_t n = snapshot->snapshot_regions.size();
   for (size_t i = 0; i != n; ++i) {
-    mc_mem_region_t region = snapshot->snapshot_regions[i];
+    mc_mem_region_t region = snapshot->snapshot_regions[i].get();
     if (!(region && region->contain(simgrid::mc::remote(addr))))
       continue;
 
@@ -157,8 +157,6 @@ Snapshot::Snapshot() :
   process(nullptr),
   num_state(0),
   heap_bytes_used(0),
-  snapshot_regions(nullptr),
-  snapshot_regions_count(0),
   enabled_processes(),
   privatization_index(0),
   stack_sizes(),
@@ -170,10 +168,6 @@ Snapshot::Snapshot() :
 
 Snapshot::~Snapshot()
 {
-  for (size_t i = 0; i < this->snapshot_regions_count; i++) {
-    delete this->snapshot_regions[i];
-  }
-  xbt_free(this->snapshot_regions);
   xbt_dynar_free(&(this->stacks));
 }
 
index 1a58db8..17c64d8 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <vector>
 #include <set>
+#include <memory>
 
 #include <simgrid_config.h>
 #include "../xbt/mmalloc/mmprivate.h"
@@ -140,8 +141,7 @@ public: // To be private
   mc_process_t process;
   int num_state;
   size_t heap_bytes_used;
-  mc_mem_region_t* snapshot_regions;
-  size_t snapshot_regions_count;
+  std::vector<std::unique_ptr<s_mc_mem_region_t>> snapshot_regions;
   std::set<pid_t> enabled_processes;
   int privatization_index;
   std::vector<size_t> stack_sizes;