Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Const ref for catch.
[simgrid.git] / src / surf / HostImpl.cpp
index bc4c7de..ad435f4 100644 (file)
@@ -37,12 +37,17 @@ HostImpl::~HostImpl()
 {
   /* All actors should be gone when the host is turned off (by the end of the simulation). */
   if (not actor_list_.empty()) {
-    std::string msg = "Shutting down host, but it's not empty:";
-    for (auto const& actor : actor_list_)
-      msg += "\n\t" + std::string(actor.get_name());
-
-    EngineImpl::get_instance()->display_all_actor_status();
-    xbt_die("%s", msg.c_str());
+    const char* msg = "Shutting down host, but it's not empty";
+    try {
+      std::string actors;
+      for (auto const& actor : actor_list_)
+        actors += "\n\t" + std::string(actor.get_name());
+
+      EngineImpl::get_instance()->display_all_actor_status();
+      xbt_die("%s:%s", msg, actors.c_str());
+    } catch (const std::bad_alloc& ba) {
+      xbt_die("%s (cannot print actor list: %s)", msg, ba.what());
+    }
   }
   for (auto const& arg : actors_at_boot_)
     delete arg;
@@ -140,7 +145,14 @@ std::vector<s4u::Disk*> HostImpl::get_disks() const
 
 s4u::VirtualMachine* HostImpl::create_vm(const std::string& name, int core_amount, size_t ramsize)
 {
-  auto* vm   = new s4u::VirtualMachine(name, get_iface(), core_amount, ramsize);
+  auto* host_vm = new kernel::resource::VirtualMachineImpl(name, get_iface(), core_amount, ramsize);
+  auto* vm      = new s4u::VirtualMachine(host_vm);
+  host_vm->set_piface(vm);
+  return create_vm(name, vm);
+}
+
+s4u::VirtualMachine* HostImpl::create_vm(const std::string& name, s4u::VirtualMachine* vm)
+{
   vms_[name] = vm->get_vm_impl();
 
   // Create a VCPU for this VM
@@ -148,7 +160,8 @@ s4u::VirtualMachine* HostImpl::create_vm(const std::string& name, int core_amoun
   for (unsigned long i = 0; i < get_iface()->get_pstate_count(); i++)
     speeds.push_back(get_iface()->get_pstate_speed(i));
 
-  auto* cpu = englobing_zone_->get_cpu_vm_model()->create_cpu(vm, speeds)->set_core_count(core_amount);
+  auto* cpu =
+      englobing_zone_->get_cpu_vm_model()->create_cpu(vm, speeds)->set_core_count(vm->get_vm_impl()->get_core_amount());
 
   if (get_iface()->get_pstate() != 0)
     cpu->set_pstate(get_iface()->get_pstate());