Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Constructor/destructor for s_mc_comm_pattern
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 5 Apr 2016 11:25:07 +0000 (13:25 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 5 Apr 2016 14:32:44 +0000 (16:32 +0200)
src/mc/CommunicationDeterminismChecker.cpp
src/mc/mc_comm_pattern.cpp
src/mc/mc_comm_pattern.h

index 23c1d53..368d4e8 100644 (file)
@@ -184,7 +184,7 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type
   xbt_dynar_t incomplete_pattern = xbt_dynar_get_as(
     incomplete_communications_pattern, issuer->pid, xbt_dynar_t);
 
-  mc_comm_pattern_t pattern = xbt_new0(s_mc_comm_pattern_t, 1);
+  mc_comm_pattern_t pattern = new s_mc_comm_pattern_t();
   pattern->data_size = -1;
   pattern->data = nullptr;
   pattern->index =
index 4dc30b9..e474dde 100644 (file)
@@ -22,7 +22,7 @@ extern "C" {
 
 mc_comm_pattern_t MC_comm_pattern_dup(mc_comm_pattern_t comm)
 {
-  mc_comm_pattern_t res = xbt_new0(s_mc_comm_pattern_t, 1);
+  mc_comm_pattern_t res = new s_mc_comm_pattern_t();
   res->index = comm->index;
   res->type = comm->type;
   res->comm_addr = comm->comm_addr;
@@ -138,10 +138,8 @@ void MC_handle_comm_pattern(
 }
 
 void MC_comm_pattern_free(mc_comm_pattern_t p)
-{
-  xbt_free(p->rdv);
-  xbt_free(p->data);
-  xbt_free(p);
+{  
+  delete p;
   p = nullptr;
 }
 
index 0360f2d..d944f3d 100644 (file)
@@ -7,7 +7,8 @@
 #ifndef SIMGRID_MC_COMM_PATTERN_H
 #define SIMGRID_MC_COMM_PATTERN_H
 
-#include <stddef.h>
+#include <cstddef>
+#include <cstring>
 
 #include <simgrid_config.h>
 #include <xbt/dynar.h>
 SG_BEGIN_DECL()
 
 typedef struct s_mc_comm_pattern{
-  int num;
+  int num = 0;
   smx_synchro_t comm_addr;
-  e_smx_comm_type_t type;
-  unsigned long src_proc;
-  unsigned long dst_proc;
-  const char *src_host;
-  const char *dst_host;
-  char *rdv;
-  ssize_t data_size;
-  void *data;
-  int tag;
-  int index;
+  e_smx_comm_type_t type = SIMIX_COMM_SEND;
+  unsigned long src_proc = 0;
+  unsigned long dst_proc = 0;
+  const char *src_host = nullptr;
+  const char *dst_host = nullptr;
+  char *rdv = nullptr;
+  ssize_t data_size = 0;
+  void *data = nullptr;
+  int tag = 0;
+  int index = 0;
+
+  s_mc_comm_pattern()
+  {
+    std::memset(&comm_addr, 0, sizeof(comm_addr));
+  }
+  ~s_mc_comm_pattern()
+  {
+    xbt_free(this->rdv);
+    xbt_free(this->data);
+  }
+
+  // No copy:
+  s_mc_comm_pattern(s_mc_comm_pattern const&) = delete;
+  s_mc_comm_pattern& operator=(s_mc_comm_pattern const&) = delete;
+
 } s_mc_comm_pattern_t, *mc_comm_pattern_t;
 
 typedef struct s_mc_list_comm_pattern{