Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[S4U] Actor: Add 'const' keyword to getter methods
[simgrid.git] / src / simix / ActorImpl.hpp
index 7fb9ab5..c650cd2 100644 (file)
 #include "src/simix/popping_private.hpp"
 #include "src/surf/PropertyHolder.hpp"
 #include <boost/intrusive/list.hpp>
+#include <functional>
 #include <list>
 #include <map>
 
 struct s_smx_process_exit_fun_t {
-  int_f_pvoid_pvoid_t fun;
+  std::function<void(int, void*)> fun;
   void *arg;
 };
 
@@ -25,15 +26,15 @@ 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::map<std::string, std::string>> properties;
+  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,
-                      std::shared_ptr<std::map<std::string, std::string>> properties, bool auto_restart)
+  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))
       , data(data)
@@ -70,15 +71,15 @@ public:
 
   smx_activity_t waiting_synchro = nullptr; /* the current blocking synchro if any */
   std::list<smx_activity_t> comms;          /* the current non-blocking communication synchros */
-  s_smx_simcall_t simcall;
-  void* userdata = nullptr;                      /* kept for compatibility, it should be replaced with moddata */
+  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;
 
-  /* Refcounting */
 private:
+  void* userdata = nullptr; /* kept for compatibility, it should be replaced with moddata */
+  /* Refcounting */
   std::atomic_int_fast32_t refcount_{0};
 
 public:
@@ -113,14 +114,14 @@ private:
   bool daemon = false;
 public:
   void daemonize();
-  bool isDaemon() { return daemon; } /** Whether this actor has been daemonized */
-  bool isSuspended() { return suspended; }
+  bool isDaemon() const { return daemon; } /** Whether this actor has been daemonized */
+  bool isSuspended() const { return suspended; }
   simgrid::s4u::Actor* restart();
   smx_activity_t suspend(ActorImpl* issuer);
   void resume();
   smx_activity_t sleep(double duration);
   void setUserData(void* data) { userdata = data; }
-  void* getUserData() { return userdata; }
+  void* getUserData() const { return userdata; }
 };
 
 /* Used to keep the list of actors blocked on a synchro  */
@@ -128,17 +129,15 @@ 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;
 
-extern "C" {
-
-XBT_PRIVATE smx_actor_t SIMIX_process_create(const char* name, std::function<void()> code, void* data, sg_host_t host,
-                                             std::map<std::string, std::string>* properties,
+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);
 
 XBT_PRIVATE void SIMIX_process_runall();
@@ -152,7 +151,6 @@ XBT_PRIVATE void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest);
 XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_actor_t process, int auto_restart);
 
 extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor);
-}
 
 XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro);
 XBT_PRIVATE smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout);