Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make msg_comm_t be a real structure again, not an alias of smx_comm_t.
[simgrid.git] / src / simix / smx_process.c
index 01a6d29..d267eb9 100644 (file)
@@ -14,7 +14,7 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
                                 "Logging specific to SIMIX (process)");
 
-static unsigned long simix_process_maxpid = 0;
+unsigned long simix_process_maxpid = 0;
 
 /**
  * \brief Returns the current agent.
@@ -36,7 +36,7 @@ XBT_INLINE smx_process_t SIMIX_process_self(void)
 void SIMIX_process_cleanup(smx_process_t process)
 {
   DEBUG1("Cleanup process %s", process->name);
-  xbt_swag_remove(process, simix_global->process_to_run);
+  /*xbt_swag_remove(process, simix_global->process_to_run);*/
   xbt_swag_remove(process, simix_global->process_list);
   xbt_swag_remove(process, process->smx_host->process_list);
   xbt_swag_insert(process, simix_global->process_to_destroy);
@@ -81,6 +81,7 @@ void SIMIX_create_maestro_process()
   maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
   maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
+  maestro->request.issuer = maestro;
 
   simix_global->maestro_process = maestro;
   return;
@@ -95,7 +96,9 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
   smx_process_t process;
 
   if (simix_global->create_process_function) {
-    process = simix_global->create_process_function(args->name,
+    simix_global->create_process_function(
+        &process,
+        args->name,
        args->code,
        args->data,
        args->hostname,
@@ -104,7 +107,9 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
        args->properties);
   }
   else {
-    process = SIMIX_process_create(args->name,
+    SIMIX_process_create(
+        &process,
+        args->name,
        args->code,
        args->data,
        args->hostname,
@@ -127,14 +132,15 @@ smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
  *
  * \return the process created
  */
-smx_process_t SIMIX_process_create(const char *name,
-                                   xbt_main_func_t code,
-                                  void *data,
-                                  const char *hostname,
-                                  int argc, char **argv,
-                                  xbt_dict_t properties) {
-
-  smx_process_t process = NULL;
+void SIMIX_process_create(smx_process_t *process,
+                          const char *name,
+                          xbt_main_func_t code,
+                          void *data,
+                          const char *hostname,
+                          int argc, char **argv,
+                          xbt_dict_t properties) {
+
+  *process = NULL;
   smx_host_t host = SIMIX_host_get_by_name(hostname);
 
   DEBUG2("Start process %s on host %s", name, hostname);
@@ -144,38 +150,36 @@ smx_process_t SIMIX_process_create(const char *name,
           hostname);
   }
   else {
-    process = xbt_new0(s_smx_process_t, 1);
+    *process = xbt_new0(s_smx_process_t, 1);
 
     xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
 
     /* Process data */
-    process->pid = simix_process_maxpid++;
-    process->name = xbt_strdup(name);
-    process->smx_host = host;
-    process->data = data;
+    (*process)->pid = simix_process_maxpid++;
+    (*process)->name = xbt_strdup(name);
+    (*process)->smx_host = host;
+    (*process)->data = data;
 
-    VERB1("Create context %s", process->name);
-    process->context = SIMIX_context_new(code, argc, argv,
-       simix_global->cleanup_process_function, process);
+    VERB1("Create context %s", (*process)->name);
+    (*process)->context = SIMIX_context_new(code, argc, argv,
+       simix_global->cleanup_process_function, *process);
 
-    process->running_ctx = xbt_new(xbt_running_ctx_t, 1);
-    XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
+    (*process)->running_ctx = xbt_new(xbt_running_ctx_t, 1);
+    XBT_RUNNING_CTX_INITIALIZE((*process)->running_ctx);
 
     /* Add properties */
-    process->properties = properties;
+    (*process)->properties = properties;
 
     /* Add the process to it's host process list */
-    xbt_swag_insert(process, host->process_list);
+    xbt_swag_insert(*process, host->process_list);
 
-    DEBUG1("Start context '%s'", process->name);
+    DEBUG1("Start context '%s'", (*process)->name);
 
     /* Now insert it in the global process list and in the process to run list */
-    xbt_swag_insert(process, simix_global->process_list);
-    DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name);
-    xbt_swag_insert(process, simix_global->process_to_run);
+    xbt_swag_insert(*process, simix_global->process_list);
+    DEBUG2("Inserting %s(%s) in the to_run list", (*process)->name, host->name);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process);
   }
-
-  return process;
 }
 
 /**
@@ -213,7 +217,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) {
        break;
 
       case SIMIX_ACTION_SYNCHRO:
-       SIMIX_synchro_stop_waiting(process, process->request);
+       SIMIX_synchro_stop_waiting(process, &process->request);
        SIMIX_synchro_destroy(process->waiting_action);
        break;
 
@@ -228,7 +232,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) {
     SIMIX_context_stop(process->context);
   }
   else {
-    xbt_swag_insert(process, simix_global->process_to_run);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
   }
 }
 
@@ -244,6 +248,8 @@ void SIMIX_process_killall(void)
   while ((p = xbt_swag_extract(simix_global->process_list)))
     SIMIX_process_kill(p, SIMIX_process_self());
 
+  SIMIX_context_runall(simix_global->process_to_run);
+
   SIMIX_process_empty_trash();
 }
 
@@ -273,8 +279,6 @@ void SIMIX_pre_process_suspend(smx_req_t req)
 
 void SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
 {
-  xbt_assert0(process, "Invalid parameters");
-
   process->suspended = 1;
 
   /* If we are suspending another process, and it is waiting on an action,
@@ -337,7 +341,7 @@ void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
       }
     }
     else {
-      xbt_swag_insert(process, simix_global->process_to_run);
+      xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
     }
   }
 }
@@ -400,14 +404,6 @@ int SIMIX_process_is_suspended(smx_process_t process)
   return process->suspended;
 }
 
-int SIMIX_process_is_enabled(smx_process_t process)
-{
-  if (process->request && SIMIX_request_is_enabled(process->request))
-    return TRUE;
-
-  return FALSE;
-}
-
 xbt_dict_t SIMIX_process_get_properties(smx_process_t process)
 {
   return process->properties;
@@ -416,8 +412,10 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process)
 void SIMIX_pre_process_sleep(smx_req_t req)
 {
   if (MC_IS_ENABLED) {
+    MC_process_clock_add(req->issuer, req->process_sleep.duration);
     req->process_sleep.result = SIMIX_DONE;
     SIMIX_request_answer(req);
+    return;
   }
   smx_action_t action = SIMIX_process_sleep(req->issuer, req->process_sleep.duration);
   xbt_fifo_push(action->request_list, req);
@@ -508,8 +506,10 @@ void SIMIX_process_yield(void)
   /* Ok, maestro returned control to us */
   DEBUG1("Maestro returned control to me: '%s'", self->name);
 
-  if (self->context->iwannadie)
+  if (self->context->iwannadie){
+    DEBUG0("I wanna die!");
     SIMIX_context_stop(self->context);
+  }
 
   if (self->doexception) {
     DEBUG0("Wait, maestro left me an exception");