From: Christian Heinrich Date: Wed, 13 Jun 2018 12:53:03 +0000 (+0200) Subject: [Plugin/Hostload] Add plugin to already existing hosts as well X-Git-Tag: v3.20~42 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/39ab2c5223ea6b0cc2a303b50207f7f31649d4b2 [Plugin/Hostload] Add plugin to already existing hosts as well Before this change, the plugin would only support hosts that were created after the plugin was initialized. This change supports pre-existing hosts as well. --- diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index 5399de2439..54d5fc98a2 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -3,6 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include #include "simgrid/plugins/load.h" #include "src/plugins/vm/VirtualMachineImpl.hpp" @@ -158,6 +159,14 @@ void sg_host_load_plugin_init() HostLoad::EXTENSION_ID = simgrid::s4u::Host::extension_create(); + if (simgrid::s4u::Engine::is_initialized()) { // If not yet initialized, this would create a new instance + // which would cause seg faults... + simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance(); + for (auto& host : e->get_all_hosts()) { + host->extension_set(new HostLoad(host)); + } + } + /* When attaching a callback into a signal, you can use a lambda as follows, or a regular function as done below */ simgrid::s4u::Host::on_creation.connect([](simgrid::s4u::Host& host) {