Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First running version after the relocation of the context module [Cristian]
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 18:04:09 +0000 (18:04 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 18:04:09 +0000 (18:04 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6496 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Virtu/sg_process.c
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/xbt_context.c
src/simix/xbt_context_sysv.c

index c001c00..218b447 100644 (file)
@@ -187,7 +187,8 @@ int gras_os_getpid(void)
   
   if (process != NULL){
     data = (gras_procdata_t *)SIMIX_process_get_data(process);
   
   if (process != NULL){
     data = (gras_procdata_t *)SIMIX_process_get_data(process);
-    return data->pid;
+    if(data != NULL)
+      return data->pid;
   }
   
   return 0;
   }
   
   return 0;
index 6433680..9d2059a 100644 (file)
@@ -211,7 +211,7 @@ void SIMIX_process_killall()
 
   SIMIX_context_empty_trash();
 
 
   SIMIX_context_empty_trash();
 
-  if (self) {
+  if (self != simix_global->maestro_process) {
     SIMIX_context_yield();
   }
 
     SIMIX_context_yield();
   }
 
@@ -221,33 +221,35 @@ void SIMIX_process_killall()
 /**
  * \brief Clean the SIMIX simulation
  *
 /**
  * \brief Clean the SIMIX simulation
  *
- * This functions remove all memories needed to the SIMIX execution
+ * This functions remove the memory used by SIMIX
  */
 void SIMIX_clean(void)
 {
  */
 void SIMIX_clean(void)
 {
-  smx_process_t p = NULL;
-
-  while ((p = xbt_swag_extract(simix_global->process_list))) {
-    SIMIX_process_kill(p);
-  }
+  /* Kill everyone (except maestro) */
+  SIMIX_process_killall();
 
 
+  /* Destroy the hosts list (and the hosts) */
   xbt_dict_free(&(simix_global->host));
   xbt_dict_free(&(simix_global->host));
+  
+  simix_config_finalize();
+  
+  /* Free the remaining data structures*/
   xbt_swag_free(simix_global->process_to_run);
   xbt_swag_free(simix_global->process_to_run);
+  xbt_swag_free(simix_global->process_to_destroy);
+  xbt_swag_free(simix_global->process_list);
+  simix_global->process_list = NULL;
   xbt_dict_free(&(simix_global->registered_functions));
   xbt_dict_free(&(simix_global->registered_functions));
-  free(simix_global);
-  simix_global = NULL;
 
 
-  surf_exit();
+  /* Let's free maestro now */
+  SIMIX_context_free(simix_global->maestro_process);
+  free(simix_global->maestro_process);  
 
 
-  /*FIXME Remove maestro's smx_process from the process_list before calling
-    SIMIX_context_mod_exit() and delete it afterwards (it should be the last one) */
+  /* Finish context module and SURF */
   SIMIX_context_mod_exit();
   SIMIX_context_mod_exit();
-  xbt_swag_free(simix_global->process_list);
-  xbt_swag_free(simix_global->process_to_destroy);
-
-  /* Let's free maestro */
-  SIMIX_context_free(simix_global->maestro_process);
-  free(simix_global->maestro_process);
+  surf_exit();
+  
+  free(simix_global);
+  simix_global = NULL;
   
   return;
 }
   
   return;
 }
@@ -295,12 +297,8 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
   }
 
   while ((process = xbt_swag_extract(simix_global->process_to_run))) {
   }
 
   while ((process = xbt_swag_extract(simix_global->process_to_run))) {
-    DEBUG2("Scheduling %s on %s",
-           process->name, process->smx_host->name);
-    simix_global->current_process = process;
+    DEBUG2("Scheduling %s on %s", process->name, process->smx_host->name);
     SIMIX_context_schedule(process);
     SIMIX_context_schedule(process);
-    /*       fflush(NULL); */
-    simix_global->current_process = NULL;
   }
 
   {
   }
 
   {
index fd4a7df..0615265 100644 (file)
@@ -27,6 +27,7 @@ void SIMIX_process_cleanup(void *arg)
 {
   xbt_swag_remove(arg, simix_global->process_to_run);
   xbt_swag_remove(arg, simix_global->process_list);
 {
   xbt_swag_remove(arg, simix_global->process_to_run);
   xbt_swag_remove(arg, simix_global->process_list);
+  xbt_swag_remove(arg, ((smx_process_t)arg)->smx_host->process_list);
   xbt_swag_insert(arg, simix_global->process_to_destroy);
 }
 
   xbt_swag_insert(arg, simix_global->process_to_destroy);
 }
 
@@ -49,11 +50,8 @@ void __SIMIX_create_maestro_process()
 
   /* Set it as the maestro process */
   simix_global->maestro_process = process;
 
   /* Set it as the maestro process */
   simix_global->maestro_process = process;
+  simix_global->current_process = process;
   
   
-  /* Now insert it in the global process list and in the process to run list */
-  /* FIXME should it be included in the process_list ??? */
-  xbt_swag_insert(process, simix_global->process_list);
-
   return;
 }
 
   return;
 }
 
@@ -196,9 +194,6 @@ void SIMIX_process_kill(smx_process_t process)
   if (process->cond)
     xbt_swag_remove(process, process->cond->sleeping);
 
   if (process->cond)
     xbt_swag_remove(process, process->cond->sleeping);
 
-  xbt_swag_remove(process, simix_global->process_to_run);
-  xbt_swag_remove(process, simix_global->process_list);
-
   DEBUG2("%p here! killing %p", simix_global->current_process, process);
   SIMIX_context_kill(process);
 
   DEBUG2("%p here! killing %p", simix_global->current_process, process);
   SIMIX_context_kill(process);
 
index da0da65..c1f1e65 100644 (file)
@@ -52,18 +52,12 @@ void SIMIX_context_mod_init(void)
 void SIMIX_context_mod_exit(void)
 {
   if (simix_global->context_factory) {
 void SIMIX_context_mod_exit(void)
 {
   if (simix_global->context_factory) {
-    smx_process_t process = NULL;
     smx_pfn_context_factory_finalize_t finalize_factory;
 
     smx_pfn_context_factory_finalize_t finalize_factory;
 
-    /* kill all the processes (except maestro)
-     * the killed processes are added in the list of the processes to destroy */
+    /* if there are living processes then kill them (except maestro) */
+    if(simix_global->process_list != NULL)
+      SIMIX_process_killall();
     
     
-    while ((process = xbt_swag_extract(simix_global->process_list)))
-      (*(simix_global->context_factory->kill)) (process);
-
-    /* destroy all processes in the list of process to destroy */
-    SIMIX_context_empty_trash();
-
     /* finalize the context factory */
     finalize_factory = simix_global->context_factory->finalize;
     (*finalize_factory) (&simix_global->context_factory);
     /* finalize the context factory */
     finalize_factory = simix_global->context_factory->finalize;
     (*finalize_factory) (&simix_global->context_factory);
@@ -234,7 +228,6 @@ void SIMIX_context_empty_trash(void)
   int i;  
 
   while ((process = xbt_swag_extract(simix_global->process_to_destroy))){
   int i;  
 
   while ((process = xbt_swag_extract(simix_global->process_to_destroy))){
-
     free(process->name);
     process->name = NULL;
   
     free(process->name);
     process->name = NULL;
   
index c091538..2847201 100644 (file)
@@ -255,7 +255,7 @@ static void smx_ctx_sysv_suspend(smx_process_t process)
   DEBUG1("Suspend context: '%s'", simix_global->current_process->name);
   smx_process_t prev_process = ((xbt_ctx_sysv_t) process->context)->prev;
 
   DEBUG1("Suspend context: '%s'", simix_global->current_process->name);
   smx_process_t prev_process = ((xbt_ctx_sysv_t) process->context)->prev;
 
-  simix_global->current_process = (smx_process_t) (((xbt_ctx_sysv_t) process->context)->prev);
+  simix_global->current_process = prev_process;
 
   ((xbt_ctx_sysv_t) process->context)->prev = NULL;
 
 
   ((xbt_ctx_sysv_t) process->context)->prev = NULL;