Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
[simgrid.git] / src / simix / smx_process.cpp
index 72651d2..0fce5df 100644 (file)
@@ -4,6 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include <boost/range/algorithm.hpp>
+
 #include "src/surf/surf_interface.hpp"
 #include "smx_private.h"
 #include "xbt/sysdep.h"
@@ -202,26 +204,6 @@ void SIMIX_process_stop(smx_process_t arg) {
   arg->context->stop();
 }
 
-void* simcall_HANDLER_process_create(
-  smx_simcall_t simcall, const char *name, xbt_main_func_t code,
-  void *data, const char *hostname, double kill_time,
-  int argc, char **argv, xbt_dict_t properties,
-  int auto_restart)
-{
-  void* res = SIMIX_process_create(
-    name, simgrid::simix::wrap_main(code, argc, argv), data, hostname,
-    kill_time, properties, auto_restart, simcall->issuer);
-  for (int i = 0; i != argc; ++i)
-    xbt_free(argv[i]);
-  xbt_free(argv);
-  return res;
-}
-
-static void kill_process(void* process)
-{
-  simix_global->kill_process_function((smx_process_t) process);
-}
-
 /**
  * \brief Internal function to create a process.
  *
@@ -257,7 +239,7 @@ smx_process_t SIMIX_process_create(
     xbt_assert(code && host != NULL, "Invalid parameters");
     /* Process data */
     process->pid = simix_process_maxpid++;
-    process->name = std::string(name);
+    process->name = simgrid::xbt::string(name);
     process->host = host;
     process->data = data;
     process->comms = xbt_fifo_new();
@@ -315,7 +297,9 @@ smx_process_t SIMIX_process_create(
     if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) {
       XBT_DEBUG("Process %s(%s) will be kill at time %f",
         process->name.c_str(), sg_host_get_name(process->host), kill_time);
-      process->kill_timer = SIMIX_timer_set(kill_time, kill_process, process);
+      process->kill_timer = SIMIX_timer_set(kill_time, [=]() {
+        simix_global->kill_process_function(process);
+      });
     }
 
     /* Tracing the process creation */
@@ -483,7 +467,14 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t issuer) {
     } else if (comm != nullptr) {
       xbt_fifo_remove(process->comms, process->waiting_synchro);
       comm->cancel();
-      xbt_fifo_remove(process->waiting_synchro->simcalls, &process->simcall);
+
+      // Remove first occurence of &process->simcall:
+      auto i = boost::range::find(
+        process->waiting_synchro->simcalls,
+        &process->simcall);
+      if (i != process->waiting_synchro->simcalls.end())
+        process->waiting_synchro->simcalls.remove(&process->simcall);
+
       comm->unref();
 
     } else if (sleep != nullptr) {
@@ -608,7 +599,7 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_process_t proces
   if (process != simcall->issuer) {
     SIMIX_simcall_answer(simcall);
   } else {
-    xbt_fifo_push(sync_suspend->simcalls, simcall);
+    sync_suspend->simcalls.push_back(simcall);
     process->waiting_synchro = sync_suspend;
     process->waiting_synchro->suspend();
   }
@@ -760,7 +751,7 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process)
 void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_process_t process, double timeout)
 {
   smx_synchro_t sync = SIMIX_process_join(simcall->issuer, process, timeout);
-  xbt_fifo_push(sync->simcalls, simcall);
+  sync->simcalls.push_back(simcall);
   simcall->issuer->waiting_synchro = sync;
 }
 
@@ -770,8 +761,9 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_synch
   if (sleep->surf_sleep) {
     sleep->surf_sleep->cancel();
 
-    smx_simcall_t simcall;
-    while ((simcall = (smx_simcall_t) xbt_fifo_shift(sleep->simcalls))) {
+    while (!sleep->simcalls.empty()) {
+      smx_simcall_t simcall = sleep->simcalls.front();
+      sleep->simcalls.pop_front();
       simcall_process_sleep__set__result(simcall, SIMIX_DONE);
       simcall->issuer->waiting_synchro = NULL;
       if (simcall->issuer->suspended) {
@@ -805,7 +797,7 @@ void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration)
     return;
   }
   smx_synchro_t sync = SIMIX_process_sleep(simcall->issuer, duration);
-  xbt_fifo_push(sync->simcalls, simcall);
+  sync->simcalls.push_back(simcall);
   simcall->issuer->waiting_synchro = sync;
 }
 
@@ -818,8 +810,6 @@ smx_synchro_t SIMIX_process_sleep(smx_process_t process, double duration)
     THROWF(host_error, 0, "Host %s failed, you cannot call this function", sg_host_get_name(host));
 
   simgrid::simix::Sleep *synchro = new simgrid::simix::Sleep();
-  synchro->name = NULL;
-
   synchro->host = host;
   synchro->surf_sleep = surf_host_sleep(host, duration);
   synchro->surf_sleep->setData(synchro);