Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify destruction of containers
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 10 Oct 2017 08:52:12 +0000 (10:52 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 10 Oct 2017 08:52:12 +0000 (10:52 +0200)
src/instr/instr_config.cpp
src/instr/instr_paje_containers.cpp
src/instr/instr_private.h

index cf20d44..44077df 100644 (file)
@@ -142,7 +142,7 @@ int TRACE_end()
     TRACE_paje_dump_buffer(1);
 
     /* destroy all data structures of tracing (and free) */
-    PJ_container_free_all();
+    delete PJ_container_get_root();
     delete PJ_type_get_root();
     rootType = nullptr;
 
index 32966ff..0ab2877 100644 (file)
@@ -132,9 +132,12 @@ simgrid::instr::Container::Container(std::string name, simgrid::instr::e_contain
 simgrid::instr::Container::~Container()
 {
   XBT_DEBUG("destroy container %s", name_.c_str());
+  // Begin with destroying my own children
+  for (auto child : children_) {
+    delete child.second;
+  }
 
-  // obligation to dump previous events because they might
-  // reference the container that is about to be destroyed
+  // obligation to dump previous events because they might reference the container that is about to be destroyed
   TRACE_last_timestamp_to_dump = surf_get_clock();
   TRACE_paje_dump_buffer(1);
 
@@ -144,10 +147,8 @@ simgrid::instr::Container::~Container()
     LogContainerDestruction(this);
   }
 
-  // remove it from allContainers data structure
+  // remove me from the allContainers data structure
   allContainers.erase(name_);
-
-  // free
 }
 
 simgrid::instr::Container* PJ_container_get(const char* name)
@@ -182,30 +183,3 @@ void PJ_container_remove_from_parent (container_t child)
     parent->children_.erase(child->name_);
   }
 }
-
-static void recursiveDestroyContainer (container_t container)
-{
-  if (container == nullptr){
-    THROWF (tracing_error, 0, "trying to recursively destroy a nullptr container");
-  }
-  XBT_DEBUG("recursiveDestroyContainer %s", container->name_.c_str());
-  for (auto child : container->children_) {
-    recursiveDestroyContainer(child.second);
-  }
-  delete container;
-}
-
-void PJ_container_free_all ()
-{
-  container_t root = PJ_container_get_root();
-  if (root == nullptr){
-    THROWF (tracing_error, 0, "trying to free all containers, but root is nullptr");
-  }
-  recursiveDestroyContainer (root);
-  rootContainer = nullptr;
-
-  //checks
-  if (not allContainers.empty()) {
-    THROWF(tracing_error, 0, "some containers still present even after destroying all of them");
-  }
-}
index 81ce04a..039c580 100644 (file)
@@ -96,7 +96,6 @@ public:
   static Value* get(const char* name, Type* father);
 };
 
-
 //--------------------------------------------------
 typedef enum {
   INSTR_HOST,
@@ -165,7 +164,6 @@ class SubVariableEvent : public PajeEvent  {
     Container* container;
     Type* type;
     double value;
-
   public:
     SubVariableEvent(double timestamp, Container* container, Type* type, double value);
     void print() override;
@@ -333,7 +331,6 @@ XBT_PUBLIC(container_t) PJ_container_get (const char *name);
 XBT_PUBLIC(simgrid::instr::Container*) PJ_container_get_or_null(const char* name);
 XBT_PUBLIC(container_t) PJ_container_get_root ();
 XBT_PUBLIC(void) PJ_container_set_root (container_t root);
-XBT_PUBLIC(void) PJ_container_free_all (void);
 XBT_PUBLIC(void) PJ_container_remove_from_parent (container_t container);
 
 /* instr_paje_types.c */