From: Martin Quinson Date: Sun, 27 Dec 2015 20:46:32 +0000 (+0100) Subject: give simgrid::Host a p_cpu field instead of relying on extensions for non-optional... X-Git-Tag: v3_13~1380 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8dadf249202bc6834a1d680b8ec8446937b3c4a6?ds=sidebyside give simgrid::Host a p_cpu field instead of relying on extensions for non-optional features --- diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp index d4d211a04b..6e102c286d 100644 --- a/include/simgrid/Host.hpp +++ b/include/simgrid/Host.hpp @@ -20,6 +20,10 @@ namespace simgrid { XBT_PUBLIC_CLASS Host : public simgrid::xbt::Extendable { + + public: + surf::Cpu *p_cpu; + private: simgrid::xbt::string name_; public: diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index f332bb75e6..fdcc13233e 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -79,7 +79,6 @@ void sg_host_init() SD_HOST_LEVEL = simgrid::Host::extension_create(__SD_workstation_destroy); SIMIX_HOST_LEVEL = simgrid::Host::extension_create(SIMIX_host_destroy); USER_HOST_LEVEL = simgrid::Host::extension_create(NULL); - simgrid::surf::Cpu::classInit(); } // ========== User data Layer ========== @@ -127,13 +126,13 @@ void sg_host_simix_destroy(sg_host_t host) { // ========== SURF CPU ============ surf_cpu_t sg_host_surfcpu(sg_host_t host) { - return host->extension(); + return host->p_cpu; } void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { - host->extension_set(simgrid::surf::Cpu::EXTENSION_ID, cpu); // FIXME: use the typesafe version + host->p_cpu = cpu; } void sg_host_surfcpu_destroy(sg_host_t host) { - host->extension_set(nullptr); + host->p_cpu = nullptr; } // ========== RoutingEdge ============ surf_RoutingEdge *sg_host_edge(sg_host_t host) { diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index a935630d10..1b843c0253 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -21,14 +21,6 @@ simgrid::surf::CpuModel *surf_cpu_model_vm; namespace simgrid { namespace surf { -simgrid::xbt::Extension Cpu::EXTENSION_ID; - -void Cpu::classInit() -{ - if (!EXTENSION_ID.valid()) - EXTENSION_ID = simgrid::Host::extension_create(); -} - /************* * Callbacks * *************/ @@ -154,7 +146,7 @@ Cpu::Cpu(Model *model, simgrid::Host *host, , m_speedScale(speedScale) , m_host(host) { - host->extension_set(Cpu::EXTENSION_ID, this); + host->p_cpu = this; // Copy the power peak array: p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr); @@ -177,7 +169,7 @@ Cpu::Cpu(Model *model, simgrid::Host *host, lmm_constraint_t constraint, , m_speedScale(speedScale) , m_host(host) { - host->extension_set(Cpu::EXTENSION_ID, this); + host->p_cpu = this; // Copy the power peak array: p_speedPeakList = xbt_dynar_new(sizeof(double), nullptr); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index a393754448..2cb2d53843 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -74,8 +74,6 @@ public: */ XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource { public: - static simgrid::xbt::Extension EXTENSION_ID; - static void classInit(); Cpu(); /** diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index b4a2a6c5ea..80ad4c2c64 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -252,7 +252,7 @@ void surf_resource_set_state(surf_cpp_resource_t resource, e_surf_resource_state } surf_action_t surf_host_sleep(sg_host_t host, double duration){ - return host->extension(simgrid::surf::Cpu::EXTENSION_ID)->sleep(duration); + return host->p_cpu->sleep(duration); } xbt_dict_t sg_host_get_properties(sg_host_t host) { @@ -272,7 +272,7 @@ int surf_host_get_core(sg_host_t host){ } surf_action_t surf_host_execute(sg_host_t host, double size){ - return host->extension(simgrid::surf::Cpu::EXTENSION_ID)->execute(size); + return host->p_cpu->execute(size); } double surf_host_get_current_power_peak(sg_host_t host){ @@ -460,8 +460,8 @@ surf_action_t surf_cpu_execute(sg_host_t cpu, double size){ return sg_host_surfcpu(cpu)->execute(size); } -surf_action_t surf_cpu_sleep(sg_host_t cpu, double duration){ - return sg_host_surfcpu(cpu)->sleep(duration); +surf_action_t surf_cpu_sleep(sg_host_t host, double duration){ + return sg_host_surfcpu(host)->sleep(duration); } double surf_action_get_start_time(surf_action_t action){