Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
refactoring and cosmetics
[simgrid.git] / src / simix / ActorImpl.hpp
index 5e9b5c2..0b4c9e6 100644 (file)
@@ -9,15 +9,14 @@
 #include "simgrid/s4u/Actor.hpp"
 #include "src/simix/popping_private.hpp"
 #include "src/surf/PropertyHolder.hpp"
-#include "xbt/swag.h"
+#include <boost/intrusive/list.hpp>
 #include <list>
 #include <map>
 
-typedef struct s_smx_process_exit_fun {
+struct s_smx_process_exit_fun_t {
   int_f_pvoid_pvoid_t fun;
   void *arg;
-} s_smx_process_exit_fun_t;
-typedef s_smx_process_exit_fun_t* smx_process_exit_fun_t;
+};
 
 namespace simgrid {
 namespace simix {
@@ -26,11 +25,23 @@ class ProcessArg {
 public:
   std::string name;
   std::function<void()> code;
-  void *data            = nullptr;
-  sg_host_t host        = nullptr;
+  voiddata            = nullptr;
+  s4u::Host* host       = nullptr;
   double kill_time      = 0.0;
   std::shared_ptr<std::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)
+      : name(name)
+      , code(std::move(code))
+      , data(data)
+      , host(host)
+      , kill_time(kill_time)
+      , properties(properties)
+      , auto_restart(auto_restart)
+  {
+  }
 };
 
 class ActorImpl : public simgrid::surf::PropertyHolder {
@@ -38,16 +49,15 @@ public:
   ActorImpl() : piface_(this) {}
   ~ActorImpl();
 
-  // TODO, replace with boost intrusive container hooks
-  s_xbt_swag_hookup_t process_hookup   = { nullptr, nullptr }; /* simix_global->process_list */
-  s_xbt_swag_hookup_t synchro_hookup   = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
-  s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
-  s_xbt_swag_hookup_t destroy_hookup   = { nullptr, nullptr }; /* simix_global->process_to_destroy */
+  boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */
+  boost::intrusive::list_member_hook<> smx_destroy_list_hook;  /* simix_global->process_to_destroy */
+  boost::intrusive::list_member_hook<> smx_synchro_hook;       /* {mutex,cond,sem}->sleeping */
 
   aid_t pid  = 0;
   aid_t ppid = -1;
   simgrid::xbt::string name;
-  const char* cname() { return name.c_str(); }
+  const simgrid::xbt::string& getName() const { return name; }
+  const char* getCname() const { return name.c_str(); }
   s4u::Host* host       = nullptr; /* the host on which the process is running */
   smx_context_t context = nullptr; /* the context (uctx/raw/thread) that executes the user function */
 
@@ -58,7 +68,6 @@ public:
   bool suspended    = false;
   bool auto_restart = false;
 
-  sg_host_t new_host             = nullptr; /* if not null, the host on which the process must migrate to */
   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;
@@ -115,6 +124,10 @@ public:
   void* getUserData() { return userdata; }
 };
 
+/* Used to keep the list of actors blocked on a synchro  */
+typedef boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
+                                                                        &ActorImpl::smx_synchro_hook>>
+    SynchroList;
 }
 }