Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Plugin/Hostload] Add plugin to already existing hosts as well
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 13 Jun 2018 12:53:03 +0000 (14:53 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 21 Jun 2018 09:55:40 +0000 (11:55 +0200)
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.

src/plugins/host_load.cpp

index 5399de2..54d5fc9 100644 (file)
@@ -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 <simgrid/s4u.hpp>
 #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<HostLoad>();
 
+  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) {