From f8890e934eccb4cc07766065689b885068d6bc65 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 17 Dec 2015 14:38:31 +0100 Subject: [PATCH] [surf] simgrid::surf::Host, add backlink and attach() method --- src/surf/host_clm03.cpp | 2 -- src/surf/host_interface.cpp | 9 +++++++++ src/surf/host_interface.hpp | 2 ++ src/surf/host_ptask_L07.cpp | 7 +------ src/surf/sg_platf.cpp | 3 +-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index fd7e4458e1..3465f78b85 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -51,9 +51,7 @@ Host *HostCLM03Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) Host *host = new simgrid::surf::HostCLM03(surf_host_model, name, NULL, (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL), netElm, cpu); - surf_callback_emit(hostCreatedCallbacks, host); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); - simgrid::Host::by_name_or_null(name)->set_facet(host); return host; } diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index 81037bc3b1..e2eb602a11 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -109,6 +109,15 @@ Host::~Host(){ surf_callback_emit(hostDestructedCallbacks, this); } +void Host::attach(simgrid::Host* host) +{ + if (p_host != nullptr) + xbt_die("Already attached to host %s", host->id().c_str()); + host->set_facet(this); + p_host = host; + surf_callback_emit(hostCreatedCallbacks, this); +} + void Host::setState(e_surf_resource_state_t state){ e_surf_resource_state_t old = Resource::getState(); Resource::setState(state); diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 915c14ade6..ed143b8836 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -129,6 +129,7 @@ public: /** @brief Host destructor */ ~Host(); + void attach(simgrid::Host* host); void setState(e_surf_resource_state_t state); /** @@ -267,6 +268,7 @@ public: xbt_dynar_t p_storage; RoutingEdge *p_netElm; Cpu *p_cpu; + simgrid::Host* p_host = nullptr; /** @brief Get the list of virtual machines on the current Host */ xbt_dynar_t getVms(); diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 0fc243c5a0..2f573c0929 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -272,12 +272,7 @@ Action *HostL07Model::executeParallelTask(int host_nb, Host *HostL07Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) { - HostL07 *host = new HostL07(this, name, NULL, netElm, cpu); - - surf_callback_emit(hostCreatedCallbacks, host); - simgrid::Host::by_name_or_create(name)->set_facet(host); - - return host; + return new HostL07(this, name, NULL, netElm, cpu); } Action *NetworkL07Model::communicate(RoutingEdge *src, RoutingEdge *dst, diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 8797417b5d..bc674ce914 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -72,8 +72,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) host->state_trace, host->properties); cpu->plug(h); - surf_host_model->createHost(host->id, net, cpu); - + surf_host_model->createHost(host->id, net, cpu)->attach(h); if (TRACE_is_enabled() && TRACE_needs_platform()) sg_instr_new_host(host); } -- 2.20.1