Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make MSG use the Host extension mechanism (at least)
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Feb 2017 22:32:34 +0000 (23:32 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 15 Feb 2017 23:40:55 +0000 (00:40 +0100)
include/simgrid/host.h
include/simgrid/s4u/host.hpp
src/msg/msg_global.cpp
src/msg/msg_host.cpp
src/msg/msg_private.h
src/s4u/s4u_host.cpp
src/simgrid/host.cpp

index 4fd737b..0808f66 100644 (file)
@@ -32,11 +32,6 @@ XBT_PUBLIC(void*) sg_host_user(sg_host_t host);
 XBT_PUBLIC(void) sg_host_user_set(sg_host_t host, void* userdata);
 XBT_PUBLIC(void) sg_host_user_destroy(sg_host_t host);
 
-// ========== MSG Layer ==============
-typedef struct s_msg_host_priv *msg_host_priv_t;
-msg_host_priv_t sg_host_msg(sg_host_t host);
-XBT_PUBLIC(void) sg_host_msg_set(sg_host_t host, msg_host_priv_t priv);
-
 // ========== Simix layer =============
 XBT_PUBLIC(smx_host_priv_t) sg_host_simix(sg_host_t host);
 
index ad4c0a0..27a2d0c 100644 (file)
@@ -131,7 +131,6 @@ public:
 
 }} // namespace simgrid::s4u
 
-extern int MSG_HOST_LEVEL;
 extern int USER_HOST_LEVEL;
 
 #endif /* SIMGRID_S4U_HOST_HPP */
index 79f02a4..97c3e86 100644 (file)
@@ -23,11 +23,6 @@ static void _sg_cfg_cb_msg_debug_multiple_use(const char *name)
   msg_global->debug_multiple_use = xbt_cfg_get_boolean(name);
 }
 
-static void MSG_host_create_(sg_host_t host)
-{
-  __MSG_host_create(host);
-}
-
 /**
  * \ingroup msg_simulation
  * \brief Initialize MSG with less verifications
@@ -55,13 +50,11 @@ void MSG_init_nocheck(int *argc, char **argv) {
     SIMIX_function_register_process_cleanup(MSG_process_cleanup_from_SIMIX);
 
     simgrid::s4u::onPlatformCreated.connect(MSG_post_create_environment);
+
+    simgrid::MsgHostExt::EXTENSION_ID = simgrid::s4u::Host::extension_create<simgrid::MsgHostExt>();
     simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host& host) {
-      MSG_host_create_(&host);
-    });
-    MSG_HOST_LEVEL = simgrid::s4u::Host::extension_create([](void *p) {
-      __MSG_host_priv_free((msg_host_priv_t) p);
+      host.extension_set<simgrid::MsgHostExt>(new simgrid::MsgHostExt());
     });
-
   }
 
   if(MC_is_active()){
index 2be2e10..edd0280 100644 (file)
@@ -11,6 +11,8 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg);
 
+simgrid::xbt::Extension<simgrid::s4u::Host, simgrid::MsgHostExt> simgrid::MsgHostExt::EXTENSION_ID;
+
 int sg_storage_max_file_descriptors = 1024;
 
 /** @addtogroup m_host_management
@@ -23,17 +25,6 @@ int sg_storage_max_file_descriptors = 1024;
  */
 
 /********************************* Host **************************************/
-msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our parameter
-{
-  msg_host_priv_t priv = xbt_new0(s_msg_host_priv_t, 1);
-
-  priv->file_descriptor_table = nullptr;
-
-  sg_host_msg_set(host,priv);
-
-  return host;
-}
-
 /** \ingroup m_host_management
  * \brief Finds a msg_host_t using its name.
  *
@@ -100,17 +91,6 @@ void MSG_host_off(msg_host_t host)
   host->turnOff();
 }
 
-/*
- * \brief Frees private data of a host (internal call only)
- */
-void __MSG_host_priv_free(msg_host_priv_t priv)
-{
-  if (priv == nullptr)
-    return;
-  delete priv->file_descriptor_table;
-  free(priv);
-}
-
 /** \ingroup m_host_management
  * \brief Return the current number MSG hosts.
  */
@@ -305,8 +285,8 @@ xbt_dict_t MSG_host_get_storage_content(msg_host_t host)
 }
 
 int __MSG_host_get_file_descriptor_id(msg_host_t host){
-  msg_host_priv_t priv = sg_host_msg(host);
-  if(!priv->file_descriptor_table){
+  simgrid::MsgHostExt* priv = host->extension<simgrid::MsgHostExt>();
+  if (priv->file_descriptor_table == nullptr) {
     priv->file_descriptor_table = new std::vector<int>(sg_storage_max_file_descriptors);
     std::iota (priv->file_descriptor_table->rbegin(), priv->file_descriptor_table->rend(), 0); // Fill with ..., 1, 0.
   }
@@ -317,6 +297,5 @@ int __MSG_host_get_file_descriptor_id(msg_host_t host){
 }
 
 void __MSG_host_release_file_descriptor_id(msg_host_t host, int id){
-  msg_host_priv_t priv = sg_host_msg(host);
-  priv->file_descriptor_table->push_back(id);
+  host->extension<simgrid::MsgHostExt>()->file_descriptor_table->push_back(id);
 }
index 4270fd8..e675c36 100644 (file)
 #include "src/kernel/activity/SynchroExec.hpp"
 #include "src/kernel/activity/SynchroComm.hpp"
 
+#include <xbt/Extendable.hpp>
+
 SG_BEGIN_DECL()
 
 /**************** datatypes **********************************/
-/********************************* Host **************************************/
-typedef struct s_msg_host_priv {
-  std::vector<int> *file_descriptor_table;
-} s_msg_host_priv_t;
+/**************************** Host Extension *********************************/
+namespace simgrid {
+class MsgHostExt {
+public:
+  static simgrid::xbt::Extension<s4u::Host, MsgHostExt> EXTENSION_ID;
+
+  ~MsgHostExt() {
+    delete file_descriptor_table;
+  }
+  std::vector<int>* file_descriptor_table = nullptr; // Created lazily on need
+};
+}
 /********************************* Task **************************************/
 
 typedef struct simdata_task {
@@ -109,7 +119,6 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global;
 /*************************************************************/
 XBT_PRIVATE msg_host_t __MSG_host_create(sg_host_t host);
 XBT_PRIVATE msg_storage_t __MSG_storage_create(smx_storage_t storage);
-XBT_PRIVATE void __MSG_host_priv_free(msg_host_priv_t priv);
 XBT_PRIVATE void __MSG_storage_destroy(msg_storage_priv_t host);
 XBT_PRIVATE void __MSG_file_destroy(msg_file_priv_t host);
 
index 0c91112..29d104a 100644 (file)
@@ -26,7 +26,6 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_route);
 
 std::unordered_map<std::string, simgrid::s4u::Host*> host_list; // FIXME: move it to Engine
 
-int MSG_HOST_LEVEL = -1;
 int USER_HOST_LEVEL = -1;
 
 namespace simgrid {
index 5ab8cdc..977068c 100644 (file)
@@ -116,14 +116,6 @@ void sg_host_user_destroy(sg_host_t host) {
   host->extension_set(USER_HOST_LEVEL, nullptr);
 }
 
-// ========== MSG Layer ==============
-msg_host_priv_t sg_host_msg(sg_host_t host) {
-  return (msg_host_priv_t) host->extension(MSG_HOST_LEVEL);
-}
-void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) {
-  host->extension_set(MSG_HOST_LEVEL, smx_host);
-}
-
 // ========== Simix layer =============
 smx_host_priv_t sg_host_simix(sg_host_t host){
   return host->extension<simgrid::simix::Host>();