Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merging changes done by Steven, Samuel and Luka, regarding simulation of StarPU-MPI
[simgrid.git] / src / simix / smx_process.cpp
similarity index 94%
rename from src/simix/smx_process.c
rename to src/simix/smx_process.cpp
index 61e32f3..bc84eb7 100644 (file)
@@ -9,11 +9,12 @@
 #include "xbt/log.h"
 #include "xbt/dict.h"
 #include "mc/mc.h"
-#include "mc/mc_replay.h"
-#include "mc/mc_client.h"
+#include "src/mc/mc_replay.h"
+#include "src/mc/mc_client.h"
+#include "src/simix/smx_private.hpp"
 
 #ifdef HAVE_SMPI
-#include "smpi/private.h"
+#include "src/smpi/private.h"
 #endif
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
@@ -28,7 +29,7 @@ unsigned long simix_process_maxpid = 0;
  *
  * \return The SIMIX process
  */
-XBT_INLINE smx_process_t SIMIX_process_self(void)
+smx_process_t SIMIX_process_self(void)
 {
   smx_context_t self_context = SIMIX_context_self();
 
@@ -62,7 +63,7 @@ void SIMIX_process_cleanup(smx_process_t process)
 
   /* cancel non-blocking communications */
   smx_synchro_t synchro;
-  while ((synchro = xbt_fifo_pop(process->comms))) {
+  while ((synchro = (smx_synchro_t) xbt_fifo_pop(process->comms))) {
 
     /* make sure no one will finish the comm after this process is destroyed,
      * because src_proc or dst_proc would be an invalid pointer */
@@ -117,7 +118,7 @@ void SIMIX_process_empty_trash(void)
 {
   smx_process_t process = NULL;
 
-  while ((process = xbt_swag_extract(simix_global->process_to_destroy))) {
+  while ((process = (smx_process_t) xbt_swag_extract(simix_global->process_to_destroy))) {
     XBT_DEBUG("Getting rid of %p",process);
 
     SIMIX_context_free(process->context);
@@ -147,7 +148,7 @@ void SIMIX_create_maestro_process()
   maestro->pid = simix_process_maxpid++;
   maestro->ppid = -1;
   maestro->name = (char *) "";
-  maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
+  maestro->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
   maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
   maestro->simcall.issuer = maestro;
@@ -167,14 +168,14 @@ void SIMIX_process_stop(smx_process_t arg) {
   /* Add the process to the list of process to restart, only if
    * the host is down
    */
-  if (arg->auto_restart && !SIMIX_host_get_state(arg->host)) {
+  if (arg->auto_restart && !sg_host_get_state(arg->host)) {
     SIMIX_host_add_auto_restart_process(arg->host,arg->name,arg->code, arg->data,
-                                        sg_host_name(arg->host),
+                                        sg_host_get_name(arg->host),
                                         SIMIX_timer_get_date(arg->kill_timer),
                                         arg->argc,arg->argv,arg->properties,
                                         arg->auto_restart);
   }
-  XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_name(arg->host));
+  XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_get_name(arg->host));
   /* stop the context */
   SIMIX_context_stop(arg->context);
 }
@@ -215,6 +216,12 @@ void* simcall_HANDLER_process_create(smx_simcall_t simcall,
                        kill_time, argc, argv, properties, auto_restart,
                        simcall->issuer);
 }
+
+static void kill_process(void* process)
+{
+  simix_global->kill_process_function((smx_process_t) process);
+}
+
 /**
  * \brief Internal function to create a process.
  *
@@ -240,7 +247,7 @@ smx_process_t SIMIX_process_create(
 
   XBT_DEBUG("Start process %s on host '%s'", name, hostname);
 
-  if (!SIMIX_host_get_state(host)) {
+  if (!sg_host_get_state(host)) {
     int i;
     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
           hostname);
@@ -287,7 +294,7 @@ smx_process_t SIMIX_process_create(
     XBT_VERB("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);
+    process->running_ctx = (xbt_running_ctx_t*) xbt_malloc0(sizeof(xbt_running_ctx_t));
     XBT_RUNNING_CTX_INITIALIZE(process->running_ctx);
 
     if(MC_is_active()){
@@ -304,13 +311,13 @@ smx_process_t SIMIX_process_create(
 
     /* Now insert it in the global process list and in the process to run list */
     xbt_swag_insert(process, simix_global->process_list);
-    XBT_DEBUG("Inserting %s(%s) in the to_run list", process->name, sg_host_name(host));
+    XBT_DEBUG("Inserting %s(%s) in the to_run list", process->name, sg_host_get_name(host));
     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
 
     if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) {
       XBT_DEBUG("Process %s(%s) will be kill at time %f", process->name,
-          sg_host_name(process->host), kill_time);
-      process->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
+          sg_host_get_name(process->host), kill_time);
+      process->kill_timer = SIMIX_timer_set(kill_time, kill_process, process);
     }
   }
   return process;
@@ -349,7 +356,7 @@ void simcall_HANDLER_process_kill(smx_simcall_t simcall, smx_process_t process)
  */
 void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
 
-  XBT_DEBUG("Killing process %s on %s", process->name, sg_host_name(process->host));
+  XBT_DEBUG("Killing process %s on %s", process->name, sg_host_get_name(process->host));
 
   process->context->iwannadie = 1;
   process->blocked = 0;
@@ -462,7 +469,7 @@ void SIMIX_process_killall(smx_process_t issuer, int reset_pid)
 {
   smx_process_t p = NULL;
 
-  while ((p = xbt_swag_extract(simix_global->process_list))) {
+  while ((p = (smx_process_t) xbt_swag_extract(simix_global->process_list))) {
     if (p != issuer) {
       SIMIX_process_kill(p,issuer);
     }
@@ -717,7 +724,7 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_synch
     surf_action_cancel(sync->sleep.surf_sleep);
 
     smx_simcall_t simcall;
-    while ((simcall = xbt_fifo_shift(sync->simcalls))) {
+    while ((simcall = (smx_simcall_t) xbt_fifo_shift(sync->simcalls))) {
       simcall_process_sleep__set__result(simcall, SIMIX_DONE);
       simcall->issuer->waiting_synchro = NULL;
       if (simcall->issuer->suspended) {
@@ -758,16 +765,15 @@ void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration)
 
 smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration)
 {
-  smx_synchro_t synchro;
   sg_host_t host = process->host;
 
   /* check if the host is active */
   if (surf_host_get_state(surf_host_resource_priv(host)) != SURF_RESOURCE_ON) {
     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
-           sg_host_name(host));
+           sg_host_get_name(host));
   }
 
-  synchro = xbt_mallocator_get(simix_global->synchro_mallocator);
+  smx_synchro_t synchro = (smx_synchro_t) xbt_mallocator_get(simix_global->synchro_mallocator);
   synchro->type = SIMIX_SYNC_SLEEP;
   synchro->name = NULL;
   synchro->category = NULL;
@@ -787,7 +793,7 @@ void SIMIX_post_process_sleep(smx_synchro_t synchro)
   e_smx_state_t state;
   xbt_assert(synchro->type == SIMIX_SYNC_SLEEP || synchro->type == SIMIX_SYNC_JOIN);
 
-  while ((simcall = xbt_fifo_shift(synchro->simcalls))) {
+  while ((simcall = (smx_simcall_t) xbt_fifo_shift(synchro->simcalls))) {
 
     switch(surf_action_get_state(synchro->sleep.surf_sleep)){
       case SURF_ACTION_FAILED:
@@ -928,10 +934,9 @@ xbt_dynar_t SIMIX_process_get_runnable(void)
 smx_process_t SIMIX_process_from_PID(int PID)
 {
   smx_process_t proc;
-  xbt_swag_foreach(proc, simix_global->process_list)
-  {
-   if(proc->pid == PID)
-   return proc;
+  xbt_swag_foreach(proc, simix_global->process_list) {
+   if (proc->pid == (unsigned long) PID)
+    return proc;
   }
   return NULL;
 }
@@ -983,12 +988,12 @@ smx_process_t simcall_HANDLER_process_restart(smx_simcall_t simcall, smx_process
 }
 /** @brief Restart a process, starting it again from the beginning. */
 smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) {
-  XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_name(process->host));
+  XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_get_name(process->host));
   //retrieve the arguments of the old process
   //FIXME: Factorize this with SIMIX_host_add_auto_restart_process ?
   s_smx_process_arg_t arg;
   arg.code = process->code;
-  arg.hostname = sg_host_name(process->host);
+  arg.hostname = sg_host_get_name(process->host);
   arg.kill_time = SIMIX_timer_get_date(process->kill_timer);
   arg.argc = process->argc;
   arg.data = process->data;