Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Inline abstract interface to factories' functions (smx_context_* func) [Cristian]
[simgrid.git] / src / simix / smx_process.c
index 0615265..eedf711 100644 (file)
@@ -31,6 +31,31 @@ void SIMIX_process_cleanup(void *arg)
   xbt_swag_insert(arg, simix_global->process_to_destroy);
 }
 
+/** Garbage collection
+ *
+ * Should be called some time to time to free the memory allocated for processes
+ * that have finished (or killed).
+ */
+void SIMIX_process_empty_trash(void)
+{ 
+  smx_process_t process = NULL;
+  int i;  
+
+  while ((process = xbt_swag_extract(simix_global->process_to_destroy))){
+    free(process->name);
+    process->name = NULL;
+  
+    if (process->argv) {
+      for (i = 0; i < process->argc; i++)
+        if (process->argv[i])
+          free(process->argv[i]);
+
+      free(process->argv);
+    }
+  
+    free(process);
+  }
+}
 
 /**
  * \brief Creates and runs the maestro process
@@ -43,7 +68,7 @@ void __SIMIX_create_maestro_process()
   process = xbt_new0(s_smx_process_t, 1);
 
   /* Process data */
-  process->name = (char *)"maestro";
+  process->name = (char *)"";
 
   /*Create the right context type (FIXME: check the return value for success)*/
   SIMIX_context_create_maestro(&process);
@@ -51,11 +76,11 @@ void __SIMIX_create_maestro_process()
   /* Set it as the maestro process */
   simix_global->maestro_process = process;
   simix_global->current_process = process;
-  
+
   return;
 }
 
-/** 
+/**
  * \brief Creates and runs a new #smx_process_t.
  *
  * A constructor for #m_process_t taking four arguments and returning the corresponding object. The structure (and the corresponding thread) is created, and put in the list of ready process.
@@ -213,7 +238,6 @@ void SIMIX_process_kill(smx_process_t process)
 void *SIMIX_process_get_data(smx_process_t process)
 {
   xbt_assert0((process != NULL), "Invalid parameters");
-
   return (process->data);
 }
 
@@ -405,7 +429,7 @@ void SIMIX_process_change_host(smx_process_t process, char *source, char *dest)
  */
 int SIMIX_process_is_suspended(smx_process_t process)
 {
-  xbt_assert0(((process != NULL), "Invalid parameters");
+  xbt_assert0((process != NULL), "Invalid parameters");
 
   return (process->suspended);
 }