Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SIMIX] Move std::function<void()> to simgrid::simix::ActorCode
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 29 Jun 2018 09:07:48 +0000 (11:07 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Fri, 29 Jun 2018 09:23:32 +0000 (11:23 +0200)
That's a typedef for the same thing but makes the code
more readable.

include/simgrid/simix.hpp
src/msg/msg_private.hpp
src/msg/msg_process.cpp
src/simix/ActorImpl.cpp
src/simix/ActorImpl.hpp
src/simix/smx_global.cpp
src/simix/smx_host.cpp
src/surf/sg_platf.cpp

index 06a9e30..f227304 100644 (file)
@@ -90,7 +90,7 @@ XBT_PUBLIC void register_function(const char* name, ActorCodeFactory factory);
  * std::map<std::string, std::string>* props: properties
  */
 typedef smx_actor_t (*smx_creation_func_t)(
-    /* name */ const char*, std::function<void()> code,
+    /* name */ const char*, simgrid::simix::ActorCode code,
     /* userdata */ void*,
     /* hostname */ sg_host_t,
     /* props */ std::unordered_map<std::string, std::string>*,
@@ -98,7 +98,7 @@ typedef smx_actor_t (*smx_creation_func_t)(
 
 XBT_PUBLIC void SIMIX_function_register_process_create(smx_creation_func_t function);
 
-XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
+XBT_PUBLIC smx_actor_t simcall_process_create(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
                                               std::unordered_map<std::string, std::string>* properties);
 
 XBT_PUBLIC smx_timer_t SIMIX_timer_set(double date, simgrid::xbt::Task<void()> callback);
index e9f8cfe..9a98d8d 100644 (file)
@@ -85,7 +85,7 @@ XBT_PUBLIC_DATA MSG_Global_t msg_global;
 
 /*************************************************************/
 XBT_PRIVATE void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_proc);
-XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data,
+XBT_PRIVATE smx_actor_t MSG_process_create_from_SIMIX(const char* name, simgrid::simix::ActorCode code, void* data,
                                                       sg_host_t host,
                                                       std::unordered_map<std::string, std::string>* properties,
                                                       smx_actor_t parent_process);
index 521170a..12084ff 100644 (file)
@@ -57,7 +57,7 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor)
 }
 
 /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
-smx_actor_t MSG_process_create_from_SIMIX(const char* name, std::function<void()> code, void* data, sg_host_t host,
+smx_actor_t MSG_process_create_from_SIMIX(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
                                           std::unordered_map<std::string, std::string>* properties,
                                           smx_actor_t /*parent_process*/)
 {
@@ -127,7 +127,7 @@ msg_process_t MSG_process_create_with_arguments(const char *name, xbt_main_func_
 msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
                                                   int argc, char **argv, xbt_dict_t properties)
 {
-  std::function<void()> function;
+  simgrid::simix::ActorCode function;
   if (code)
     function = simgrid::xbt::wrap_main(code, argc, static_cast<const char* const*>(argv));
 
@@ -146,7 +146,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun
   return res;
 }
 
-msg_process_t MSG_process_create_from_stdfunc(const char* name, std::function<void()> code, void* data, msg_host_t host,
+msg_process_t MSG_process_create_from_stdfunc(const char* name, simgrid::simix::ActorCode code, void* data, msg_host_t host,
                                               std::unordered_map<std::string, std::string>* properties)
 {
   xbt_assert(code != nullptr && host != nullptr, "Invalid parameters: host and code params must not be nullptr");
index e45266f..fe72f94 100644 (file)
@@ -247,7 +247,7 @@ smx_activity_t ActorImpl::sleep(double duration)
   return synchro;
 }
 
-void create_maestro(std::function<void()> code)
+void create_maestro(simgrid::simix::ActorCode code)
 {
   smx_actor_t maestro = nullptr;
   /* Create maestro process and initialize it */
@@ -257,7 +257,7 @@ void create_maestro(std::function<void()> code)
   maestro->setUserData(nullptr);
 
   if (not code) {
-    maestro->context = SIMIX_context_new(std::function<void()>(), nullptr, maestro);
+    maestro->context = SIMIX_context_new(simgrid::simix::ActorCode(), nullptr, maestro);
   } else {
     if (not simix_global)
       xbt_die("simix is not initialized, please call MSG_init first");
@@ -287,7 +287,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data)
  *
  * \return the process created
  */
-smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, void* data, simgrid::s4u::Host* host,
+smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host,
                                  std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_process)
 {
 
@@ -810,7 +810,7 @@ smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void*
   return res;
 }
 
-smx_actor_t simcall_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
+smx_actor_t simcall_process_create(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
                                    std::unordered_map<std::string, std::string>* properties)
 {
   if (name == nullptr)
index 81c6326..3dd5f0c 100644 (file)
@@ -26,14 +26,14 @@ namespace actor {
 class ProcessArg {
 public:
   std::string name;
-  std::function<void()> code;
+  simgrid::simix::ActorCode code;
   void* data            = nullptr;
   s4u::Host* host       = nullptr;
   double kill_time      = 0.0;
   std::shared_ptr<std::unordered_map<std::string, std::string>> properties;
   bool auto_restart     = false;
   ProcessArg()          = default;
-  explicit ProcessArg(std::string name, std::function<void()> code, void* data, s4u::Host* host, double kill_time,
+  explicit ProcessArg(std::string name, simgrid::simix::ActorCode code, void* data, s4u::Host* host, double kill_time,
                       std::shared_ptr<std::unordered_map<std::string, std::string>> properties, bool auto_restart)
       : name(name)
       , code(std::move(code))
@@ -74,7 +74,7 @@ public:
   s_smx_simcall simcall;
   std::vector<s_smx_process_exit_fun_t> on_exit; /* list of functions executed when the process dies */
 
-  std::function<void()> code;
+  simgrid::simix::ActorCode code;
   smx_timer_t kill_timer = nullptr;
 
 private:
@@ -129,14 +129,14 @@ typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImp
                                                                         &ActorImpl::smx_synchro_hook>>
     SynchroList;
 
-XBT_PUBLIC void create_maestro(std::function<void()> code);
+XBT_PUBLIC void create_maestro(simgrid::simix::ActorCode code);
 }
 } // namespace kernel
 } // namespace simgrid
 
 typedef simgrid::kernel::actor::ActorImpl* smx_actor_t;
 
-XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
+XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
                                              std::unordered_map<std::string, std::string>* properties,
                                              smx_actor_t parent_process);
 
index 1291451..bb06cae 100644 (file)
@@ -163,7 +163,7 @@ simgrid::config::Flag<double> breakpoint{"simix/breakpoint",
 }
 }
 
-static std::function<void()> maestro_code;
+static simgrid::simix::ActorCode maestro_code;
 void SIMIX_set_maestro(void (*code)(void*), void* data)
 {
 #ifdef _WIN32
index 6590640..ecd8634 100644 (file)
@@ -78,7 +78,7 @@ const char* sg_host_self_get_name()
  * The processes will only be restarted once, meaning that you will have to register the process
  * again to restart the process again.
  */
-void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, std::function<void()> code, void* data,
+void SIMIX_host_add_auto_restart_process(sg_host_t host, const char* name, simgrid::simix::ActorCode code, void* data,
                                          double kill_time, std::unordered_map<std::string, std::string>* properties,
                                          int auto_restart)
 {
index f521fd9..7dd21c8 100644 (file)
@@ -437,7 +437,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
   bool auto_restart = actor->on_failure != simgrid::kernel::routing::ActorOnFailure::DIE;
 
   std::string actor_name     = actor->args[0];
-  std::function<void()> code = factory(std::move(actor->args));
+  simgrid::simix::ActorCode code = factory(std::move(actor->args));
   std::shared_ptr<std::unordered_map<std::string, std::string>> properties(actor->properties);
 
   simgrid::kernel::actor::ProcessArg* arg =