X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c8997e63383c66e43ffde29d356fdddb65d65d81..cc9460b0958168a1f9adec8208d190bf128ce6cc:/src/surf/virtual_machine.cpp diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index de4df13235..1666df5034 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -4,13 +4,14 @@ /* 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 "cpu_cas01.hpp" #include "virtual_machine.hpp" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, - "Logging specific to the SURF VM module"); +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm, surf, "Logging specific to the SURF VM module"); -simgrid::surf::VMModel *surf_vm_model = NULL; +simgrid::surf::VMModel *surf_vm_model = nullptr; namespace simgrid { namespace surf { @@ -19,38 +20,39 @@ namespace surf { * Callbacks * *************/ -simgrid::xbt::signal VMCreatedCallbacks; -simgrid::xbt::signal VMDestructedCallbacks; -simgrid::xbt::signal VMStateChangedCallbacks; +simgrid::xbt::signal onVmCreation; +simgrid::xbt::signal onVmDestruction; +simgrid::xbt::signal onVmStateChange; /********* * Model * *********/ -VMModel::vm_list_t VMModel::ws_vms; +std::deque VirtualMachine::allVms_; /************ * Resource * ************/ -VirtualMachine::VirtualMachine(HostModel *model, const char *name, xbt_dict_t props, simgrid::s4u::Host *hostPM) -: HostImplem(model, name, props, NULL, NULL, NULL) -, p_hostPM(hostPM) +VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u::Host *hostPM) +: HostImpl(model, name, nullptr, nullptr, nullptr) +, hostPM_(hostPM) { - VMModel::ws_vms.push_back(*this); - simgrid::s4u::Host::by_name_or_create(name)->extension_set(this); + allVms_.push_back(this); + piface = simgrid::s4u::Host::by_name_or_create(name); + piface->extension_set(this); } /* - * A physical host does not disappear in the current SimGrid code, but a VM may - * disappear during a simulation. + * A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation. */ VirtualMachine::~VirtualMachine() { - VMDestructedCallbacks(this); - VMModel::ws_vms.erase(VMModel::vm_list_t::s_iterator_to(*this)); + onVmDestruction(this); + allVms_.erase( find(allVms_.begin(), allVms_.end(), this) ); + /* Free the cpu_action of the VM. */ - XBT_ATTRIB_UNUSED int ret = p_action->unref(); + XBT_ATTRIB_UNUSED int ret = action_->unref(); xbt_assert(ret == 1, "Bug: some resource still remains"); } @@ -64,19 +66,19 @@ void VirtualMachine::setState(e_surf_vm_state_t state) { void VirtualMachine::turnOn() { if (isOff()) { Resource::turnOn(); - VMStateChangedCallbacks(this); + onVmStateChange(this); } } void VirtualMachine::turnOff() { if (isOn()) { Resource::turnOff(); - VMStateChangedCallbacks(this); + onVmStateChange(this); } } /** @brief returns the physical machine on which the VM is running **/ sg_host_t VirtualMachine::getPm() { - return p_hostPM; + return hostPM_; } }