From 4d0b9e814c4a70a167bfcb16197fbcc9a1f49305 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 15 Oct 2016 17:31:43 +0200 Subject: [PATCH] one step further to sort out the spagetti plate of AS creation --- src/kernel/routing/AsImpl.cpp | 3 +++ src/s4u/s4u_host.cpp | 6 +++--- src/surf/sg_platf.cpp | 7 ++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/kernel/routing/AsImpl.cpp b/src/kernel/routing/AsImpl.cpp index 38b857ee58..2f50e554f5 100644 --- a/src/kernel/routing/AsImpl.cpp +++ b/src/kernel/routing/AsImpl.cpp @@ -16,6 +16,9 @@ namespace simgrid { AsImpl::AsImpl(As* father, const char* name) : As(father, name) { + xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, name, ROUTING_ASR_LEVEL), + "Refusing to create a second AS called \"%s\".", name); + netcard_ = new simgrid::kernel::routing::NetCardImpl(name, simgrid::kernel::routing::NetCard::Type::As, static_cast(father)); xbt_lib_set(as_router_lib, name, ROUTING_ASR_LEVEL, (void*)netcard_); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 66a13a97a0..a6022e6e0f 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -40,6 +40,7 @@ simgrid::xbt::signal Host::onStateChange; Host::Host(const char* name) : name_(name) { + xbt_dict_set(host_list, name, this, nullptr); } Host::~Host() { @@ -68,10 +69,9 @@ Host* Host::by_name_or_null(const char* name) Host* Host::by_name_or_create(const char* name) { Host* host = by_name_or_null(name); - if (host == nullptr) { + if (host == nullptr) host = new Host(name); - xbt_dict_set(host_list, name, host, nullptr); - } + return host; } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 2cf24725b2..db14195376 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -811,9 +811,6 @@ simgrid::s4u::As * sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) surf_config_models_setup(); } - xbt_assert(nullptr == xbt_lib_get_or_null(as_router_lib, AS->id, ROUTING_ASR_LEVEL), - "Refusing to create a second AS called \"%s\".", AS->id); - _sg_cfg_init_status = 2; /* HACK: direct access to the global controlling the level of configuration to prevent * any further config now that we created some real content */ @@ -859,14 +856,14 @@ simgrid::s4u::As * sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) if (current_routing == nullptr && routing_platf->root_ == nullptr) { /* it is the first one */ routing_platf->root_ = new_as; - } else if (current_routing != nullptr && routing_platf->root_ != nullptr) { - xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id), "The AS '%s' already exists", AS->id); + } else if (current_routing != nullptr && routing_platf->root_ != nullptr) { /* set the father behavior */ if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset) current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::recursive; /* add to the sons dictionary */ xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, nullptr); + } else { THROWF(arg_error, 0, "All defined components must belong to a AS"); } -- 2.20.1