Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a deque instead of an intrusive hook for all VMs
[simgrid.git] / src / surf / vm_hl13.cpp
index fde670b..9dd72aa 100644 (file)
@@ -4,8 +4,6 @@
 /* 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 <algorithm>
-
 #include <simgrid/host.h>
 
 #include "cpu_cas01.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_vm);
 
-void surf_vm_model_init_HL13(void){
+void surf_vm_model_init_HL13(){
   if (surf_cpu_model_vm) {
     surf_vm_model = new simgrid::surf::VMHL13Model();
-    simgrid::surf::Model *model = surf_vm_model;
-    xbt_dynar_push(all_existing_models, &model);
+    all_existing_models->push_back(surf_vm_model);
   }
 }
 
@@ -31,11 +28,11 @@ VMHL13Model::VMHL13Model() : VMModel() {}
 
 void VMHL13Model::updateActionsState(double /*now*/, double /*delta*/) {}
 
-VirtualMachine *VMHL13Model::createVM(const char *name, sg_host_t host_PM)
+s4u::Host *VMHL13Model::createVM(const char *name, sg_host_t host_PM)
 {
   VirtualMachine* vm = new VMHL13(this, name, host_PM);
-  VMCreatedCallbacks(vm);
-  return vm;
+  onVmCreation(vm);
+  return vm->piface;
 }
 
 /* In the real world, processes on the guest operating system will be somewhat degraded due to virtualization overhead.
@@ -70,8 +67,7 @@ double VMHL13Model::next_occuring_event(double now)
    **/
 
   /* iterate for all virtual machines */
-  for (VMModel::vm_list_t::iterator iter = VMModel::ws_vms.begin(); iter !=  VMModel::ws_vms.end(); ++iter) {
-    VirtualMachine *ws_vm = &*iter;
+  for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
     Cpu *cpu = ws_vm->p_cpu;
     xbt_assert(cpu, "cpu-less host");
 
@@ -99,7 +95,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, sg_host_t host_PM)
  : VirtualMachine(model, name, host_PM)
 {
   /* Currently, we assume a VM has no storage. */
-  p_storage = NULL;
+  p_storage = nullptr;
 
   /* Currently, a VM uses the network resource of its physical host. In
    * host_lib, this network resource object is referred from two different keys.
@@ -107,7 +103,7 @@ VMHL13::VMHL13(VMModel *model, const char* name, sg_host_t host_PM)
    * from the VM name, we have to make sure that the system does not call the
    * free callback for the network resource object. The network resource object
    * is still used by the physical machine. */
-  sg_host_t host_VM = sg_host_by_name_or_create(name);
+  sg_host_t host_VM = simgrid::s4u::Host::by_name_or_create(name);
   host_VM->pimpl_netcard = host_PM->pimpl_netcard;
 
   p_vm_state = SURF_VM_STATE_CREATED;
@@ -127,6 +123,9 @@ VMHL13::VMHL13(VMModel *model, const char* name, sg_host_t host_PM)
 
   XBT_VERB("Create VM(%s)@PM(%s) with %ld mounted disks", name, hostPM_->name().c_str(), xbt_dynar_length(p_storage));
 }
+VMHL13::~VMHL13() {
+  delete p_cpu;
+}
 
 void VMHL13::suspend()
 {
@@ -202,9 +201,5 @@ void VMHL13::setBound(double bound){
  action_->setBound(bound);
 }
 
-void VMHL13::setAffinity(Cpu *cpu, unsigned long mask){
- action_->setAffinity(cpu, mask);
-}
-
 }
 }