From: Martin Quinson Date: Sun, 28 Aug 2016 15:46:32 +0000 (+0200) Subject: use a typed extension for simix::Host X-Git-Tag: v3_14~476 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/90f32f7c90becc16c9d62c3e2aee19b904698b3d use a typed extension for simix::Host --- diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index e3f39ba0c6..a54cf12440 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -115,7 +115,6 @@ public: }} // namespace simgrid::s4u extern int MSG_HOST_LEVEL; -extern int SIMIX_HOST_LEVEL; extern int USER_HOST_LEVEL; #endif /* SIMGRID_S4U_HOST_HPP */ diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 0d3cad43ac..a75aea9657 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -21,7 +21,6 @@ #include "simgrid/s4u/storage.hpp" int MSG_HOST_LEVEL = -1; -int SIMIX_HOST_LEVEL = -1; int USER_HOST_LEVEL = -1; namespace simgrid { @@ -133,7 +132,7 @@ void Host::setProperty(const char*key, const char *value){ xbt_swag_t Host::processes() { return simgrid::simix::kernelImmediate([&]() { - return ((smx_host_priv_t)this->extension(SIMIX_HOST_LEVEL))->process_list; + return this->extension()->process_list; }); } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 701b7f469c..1d32fc2d42 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -91,14 +91,15 @@ void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) { } // ========== Simix layer ============= +#include "src/simix/smx_host_private.h" smx_host_priv_t sg_host_simix(sg_host_t host){ - return (smx_host_priv_t) host->extension(SIMIX_HOST_LEVEL); + return host->extension(); } void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) { - host->extension_set(SIMIX_HOST_LEVEL, smx_host); + host->extension_set(smx_host); } void sg_host_simix_destroy(sg_host_t host) { - host->extension_set(SIMIX_HOST_LEVEL, nullptr); + host->extension_set(nullptr); } // ========= storage related functions ============ diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 3b9bcdbeed..a47eaecd5a 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -228,7 +228,6 @@ void SIMIX_global_init(int *argc, char **argv) simgrid::s4u::Host::onCreation.connect([](simgrid::s4u::Host& host) { SIMIX_host_create(&host); }); - SIMIX_HOST_LEVEL = simgrid::s4u::Host::extension_create(SIMIX_host_destroy); simgrid::surf::storageCreatedCallbacks.connect([](simgrid::surf::Storage* storage) { const char* name = storage->getName(); diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 8f80f02c70..d2d8550198 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -19,11 +19,37 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts"); namespace simgrid { namespace simix { + simgrid::xbt::Extension Host::EXTENSION_ID; + Host::Host() { + if (!EXTENSION_ID.valid()) + EXTENSION_ID = simgrid::s4u::Host::extension_create(); + simgrid::simix::ActorImpl act; process_list = xbt_swag_new(xbt_swag_offset(act, host_proc_hookup)); } + + Host::~Host() + { + /* Clean Simulator data */ + if (xbt_swag_size(process_list) != 0) { + char *msg = xbt_strdup("Shutting down host, but it's not empty:"); + char *tmp; + smx_actor_t process = nullptr; + + xbt_swag_foreach(process, process_list) { + tmp = bprintf("%s\n\t%s", msg, process->name.c_str()); + free(msg); + msg = tmp; + } + SIMIX_display_process_status(); + THROWF(arg_error, 0, "%s", msg); + } + xbt_dynar_free(&auto_restart_processes); + xbt_dynar_free(&boot_processes); + xbt_swag_free(process_list); + } } } @@ -97,39 +123,6 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer) } } -/** - * \brief Internal function to destroy a SIMIX host. - * - * \param h the host to destroy (a sg_host_t) - */ -void SIMIX_host_destroy(void *h) -{ - smx_host_priv_t host = static_cast(h); - - xbt_assert((host != nullptr), "Invalid parameters"); - - /* Clean Simulator data */ - if (xbt_swag_size(host->process_list) != 0) { - char *msg = xbt_strdup("Shutting down host, but it's not empty:"); - char *tmp; - smx_actor_t process = nullptr; - - xbt_swag_foreach(process, host->process_list) { - tmp = bprintf("%s\n\t%s", msg, process->name.c_str()); - free(msg); - msg = tmp; - } - SIMIX_display_process_status(); - THROWF(arg_error, 0, "%s", msg); - } - xbt_dynar_free(&host->auto_restart_processes); - xbt_dynar_free(&host->boot_processes); - xbt_swag_free(host->process_list); - - /* Clean host structure */ - delete host; -} - sg_host_t SIMIX_host_self() { smx_actor_t process = SIMIX_process_self(); diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 363983eda3..a3a496fbd8 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -10,6 +10,7 @@ #include #include +#include #include "simgrid/simix.h" #include "popping_private.h" @@ -23,7 +24,10 @@ namespace simgrid { namespace simix { class Host { public: + static simgrid::xbt::Extension EXTENSION_ID; + explicit Host(); + virtual ~Host(); xbt_swag_t process_list; xbt_dynar_t auto_restart_processes = nullptr; @@ -35,7 +39,6 @@ typedef simgrid::simix::Host s_smx_host_priv_t; XBT_PRIVATE void _SIMIX_host_free_process_arg(void *); XBT_PRIVATE void SIMIX_host_create(sg_host_t host); -XBT_PRIVATE void SIMIX_host_destroy(void *host); XBT_PRIVATE void SIMIX_host_add_auto_restart_process(sg_host_t host, const char *name,