X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/10ceac5fd14fb0426b5c93bda85676a79b02d0be..90f32f7c90becc16c9d62c3e2aee19b904698b3d:/src/simix/smx_host.cpp diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 6f932c5bfa..d2d8550198 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -17,17 +17,46 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, "SIMIX hosts"); -/** @brief Internal function to create a SIMIX host. */ -void SIMIX_host_create(sg_host_t host) // FIXME: braindead prototype. Take sg_host as parameter -{ - smx_host_priv_t smx_host = xbt_new0(s_smx_host_priv_t, 1); +namespace simgrid { + namespace simix { + simgrid::xbt::Extension Host::EXTENSION_ID; + + Host::Host() + { + if (!EXTENSION_ID.valid()) + EXTENSION_ID = simgrid::s4u::Host::extension_create(); - /* Host structure */ - simgrid::simix::ActorImpl proc; - smx_host->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); + 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); + } + } +} - /* Update global variables */ - sg_host_simix_set(host, smx_host); +/** @brief Internal function to create a SIMIX host. */ +void SIMIX_host_create(sg_host_t host) +{ + sg_host_simix_set(host, new simgrid::simix::Host()); } /** @brief Start the host if it is off */ @@ -94,40 +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 */ - free(host); - return; -} - sg_host_t SIMIX_host_self() { smx_actor_t process = SIMIX_process_self();