Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill a stupid function. Let's do regular C++
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 16 Oct 2016 00:01:22 +0000 (02:01 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 16 Oct 2016 00:01:22 +0000 (02:01 +0200)
include/simgrid/s4u/host.hpp
src/s4u/s4u_host.cpp
src/simix/smx_vm.cpp
src/surf/network_ns3.cpp
src/surf/sg_platf.cpp
src/surf/virtual_machine.cpp

index 698e64f..4e59267 100644 (file)
@@ -42,12 +42,9 @@ namespace s4u {
 XBT_PUBLIC_CLASS Host :
   public simgrid::xbt::Extendable<Host> {
 
 XBT_PUBLIC_CLASS Host :
   public simgrid::xbt::Extendable<Host> {
 
-private:
+public:
   explicit Host(const char *name);
   explicit Host(const char *name);
-public: // TODO, make me private
-  ~Host();
-  /** Do not use this function, it should be private */
-  static Host* by_name_or_create(const char* name);
+  ~Host(); // TODO, make me private
 
   /** Retrieves an host from its name, or return nullptr */
   static Host* by_name_or_null(const char* name);
 
   /** Retrieves an host from its name, or return nullptr */
   static Host* by_name_or_null(const char* name);
index ce44cd7..3181507 100644 (file)
@@ -40,6 +40,7 @@ simgrid::xbt::signal<void(Host&)> Host::onStateChange;
 Host::Host(const char* name)
   : name_(name)
 {
 Host::Host(const char* name)
   : name_(name)
 {
+  xbt_assert(sg_host_by_name(name) == nullptr, "Refusing to create a second host named '%s'.", name);
   xbt_dict_set(host_list, name, this, nullptr);
 }
 
   xbt_dict_set(host_list, name, this, nullptr);
 }
 
@@ -66,14 +67,6 @@ Host* Host::by_name_or_null(const char* name)
     });
   return (Host*) xbt_dict_get_or_null(host_list, name);
 }
     });
   return (Host*) xbt_dict_get_or_null(host_list, name);
 }
-Host* Host::by_name_or_create(const char* name)
-{
-  Host* host = by_name_or_null(name);
-  if (host == nullptr)
-    host = new Host(name);
-
-  return host;
-}
 
 Host *Host::current(){
   smx_actor_t smx_proc = SIMIX_process_self();
 
 Host *Host::current(){
   smx_actor_t smx_proc = SIMIX_process_self();
index faecc81..6c99ae8 100644 (file)
@@ -298,11 +298,12 @@ void simcall_HANDLER_vm_shutdown(smx_simcall_t simcall, sg_host_t vm)
   SIMIX_vm_shutdown(vm, simcall->issuer);
 }
 
   SIMIX_vm_shutdown(vm, simcall->issuer);
 }
 
-/**
- * @brief Function to destroy a SIMIX VM host.
- *
- * @param vm the vm host to destroy (a sg_host_t)
- */
+extern xbt_dict_t host_list; // FIXME:killme don't dupplicate the content of s4u::Host this way
+                             /**
+                              * @brief Function to destroy a SIMIX VM host.
+                              *
+                              * @param vm the vm host to destroy (a sg_host_t)
+                              */
 void SIMIX_vm_destroy(sg_host_t vm)
 {
   /* this code basically performs a similar thing like SIMIX_host_destroy() */
 void SIMIX_vm_destroy(sg_host_t vm)
 {
   /* this code basically performs a similar thing like SIMIX_host_destroy() */
@@ -319,4 +320,7 @@ void SIMIX_vm_destroy(sg_host_t vm)
   /* Don't free these things twice: they are the ones of my physical host */
   vm->pimpl_cpu = nullptr;
   vm->pimpl_netcard = nullptr;
   /* Don't free these things twice: they are the ones of my physical host */
   vm->pimpl_cpu = nullptr;
   vm->pimpl_netcard = nullptr;
+
+  if (xbt_dict_get_or_null(host_list, vm->name().c_str()))
+    xbt_dict_remove(host_list, vm->name().c_str());
 }
 }
index fed3633..515ce2c 100644 (file)
@@ -73,7 +73,7 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster)
   for (int i : *cluster->radicals) {
     char* router_id = bprintf("router_%s%d%s", cluster->prefix, i, cluster->suffix);
 
   for (int i : *cluster->radicals) {
     char* router_id = bprintf("router_%s%d%s", cluster->prefix, i, cluster->suffix);
 
-    simgrid::s4u::Host* router = simgrid::s4u::Host::by_name_or_create(router_id);
+    simgrid::s4u::Host* router = new simgrid::s4u::Host(router_id);
     ns3_add_host(*router);
 
     // Create private link
     ns3_add_host(*router);
 
     // Create private link
index 632ae08..59997d9 100644 (file)
@@ -75,8 +75,6 @@ void sg_platf_exit() {
 /** @brief Add an "host" to the current AS */
 void sg_platf_new_host(sg_platf_host_cbarg_t host)
 {
 /** @brief Add an "host" to the current AS */
 void sg_platf_new_host(sg_platf_host_cbarg_t host)
 {
-  xbt_assert(sg_host_by_name(host->id) == nullptr, "Refusing to create a second host named '%s'.", host->id);
-
   simgrid::kernel::routing::AsImpl* current_routing = routing_get_current();
   if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::base;
   simgrid::kernel::routing::AsImpl* current_routing = routing_get_current();
   if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::base;
@@ -84,7 +82,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
   simgrid::kernel::routing::NetCard *netcard =
       new simgrid::kernel::routing::NetCardImpl(host->id, simgrid::kernel::routing::NetCard::Type::Host, current_routing);
 
   simgrid::kernel::routing::NetCard *netcard =
       new simgrid::kernel::routing::NetCardImpl(host->id, simgrid::kernel::routing::NetCard::Type::Host, current_routing);
 
-  sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
+  simgrid::s4u::Host* h = new simgrid::s4u::Host(host->id);
   h->pimpl_netcard = netcard;
 
   if(mount_list) {
   h->pimpl_netcard = netcard;
 
   if(mount_list) {
index 31de254..79a112b 100644 (file)
@@ -109,7 +109,7 @@ VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u:
 {
   /* Register this VM to the list of all VMs */
   allVms_.push_back(this);
 {
   /* Register this VM to the list of all VMs */
   allVms_.push_back(this);
-  piface_ = simgrid::s4u::Host::by_name_or_create(name);
+  piface_ = new simgrid::s4u::Host(name);
   piface_->extension_set<simgrid::surf::HostImpl>(this);
 
   /* Currently, we assume a VM has no storage. */
   piface_->extension_set<simgrid::surf::HostImpl>(this);
 
   /* Currently, we assume a VM has no storage. */
@@ -121,7 +121,7 @@ VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u:
    * 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. */
    * 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 = simgrid::s4u::Host::by_name_or_create(name);
+  sg_host_t host_VM      = piface_;
   host_VM->pimpl_netcard = host_PM->pimpl_netcard;
 
   vmState_ = SURF_VM_STATE_CREATED;
   host_VM->pimpl_netcard = host_PM->pimpl_netcard;
 
   vmState_ = SURF_VM_STATE_CREATED;
@@ -130,8 +130,7 @@ VirtualMachine::VirtualMachine(HostModel *model, const char *name, simgrid::s4u:
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   CpuCas01 *sub_cpu = dynamic_cast<CpuCas01*>(host_PM->pimpl_cpu);
 
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   CpuCas01 *sub_cpu = dynamic_cast<CpuCas01*>(host_PM->pimpl_cpu);
 
-  cpu_ = surf_cpu_model_vm->createCpu(host_VM, // the machine hosting the VM
-      sub_cpu->getSpeedPeakList(), 1 /*cores*/);
+  cpu_ = surf_cpu_model_vm->createCpu(host_VM, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
   if (sub_cpu->getPState() != 0)
     cpu_->setPState(sub_cpu->getPState());
 
   if (sub_cpu->getPState() != 0)
     cpu_->setPState(sub_cpu->getPState());