From: Martin Quinson Date: Wed, 15 Feb 2017 22:32:34 +0000 (+0100) Subject: make MSG use the Host extension mechanism (at least) X-Git-Tag: v3_15~370 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/32df9acdb9c57513bf704fab767117eaccdcecc9 make MSG use the Host extension mechanism (at least) --- diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 4fd737bff0..0808f663ce 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -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); diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index ad4c0a0f91..27a2d0c8bb 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -131,7 +131,6 @@ public: }} // namespace simgrid::s4u -extern int MSG_HOST_LEVEL; extern int USER_HOST_LEVEL; #endif /* SIMGRID_S4U_HOST_HPP */ diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index 79f02a4f8f..97c3e86e70 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -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::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(new simgrid::MsgHostExt()); }); - } if(MC_is_active()){ diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index 2be2e10d4e..edd0280535 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -11,6 +11,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg); +simgrid::xbt::Extension 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(); + if (priv->file_descriptor_table == nullptr) { priv->file_descriptor_table = new std::vector(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()->file_descriptor_table->push_back(id); } diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 4270fd8771..e675c36740 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -12,13 +12,23 @@ #include "src/kernel/activity/SynchroExec.hpp" #include "src/kernel/activity/SynchroComm.hpp" +#include + SG_BEGIN_DECL() /**************** datatypes **********************************/ -/********************************* Host **************************************/ -typedef struct s_msg_host_priv { - std::vector *file_descriptor_table; -} s_msg_host_priv_t; +/**************************** Host Extension *********************************/ +namespace simgrid { +class MsgHostExt { +public: + static simgrid::xbt::Extension EXTENSION_ID; + + ~MsgHostExt() { + delete file_descriptor_table; + } + std::vector* 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); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 0c91112668..29d104a225 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -26,7 +26,6 @@ XBT_LOG_EXTERNAL_CATEGORY(surf_route); std::unordered_map host_list; // FIXME: move it to Engine -int MSG_HOST_LEVEL = -1; int USER_HOST_LEVEL = -1; namespace simgrid { diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 5ab8cdc2a2..977068ce62 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -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();