From d73445fc66e276519574abf99687ff0e8b600cc6 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 24 Nov 2015 12:54:26 +0100 Subject: [PATCH] [surf] Factorize some CPU registration code in sg_host_surfcpu_register() (DRY) --- include/simgrid/host.h | 1 + src/simgrid/host.cpp | 6 ++++++ src/surf/cpu_cas01.cpp | 5 +---- src/surf/cpu_ti.cpp | 4 +--- src/surf/host_ptask_L07.cpp | 5 +---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index b422c4fc33..c6fb94364b 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -53,6 +53,7 @@ DEFINE_EXTERNAL_CLASS(Cpu); typedef Cpu *surf_cpu_t; XBT_PUBLIC(surf_cpu_t) sg_host_surfcpu(sg_host_t host); XBT_PUBLIC(void) sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu); +XBT_PUBLIC(void) sg_host_surfcpu_register(sg_host_t host, surf_cpu_t cpu); XBT_PUBLIC(void) sg_host_surfcpu_destroy(sg_host_t host); // ========== RoutingEdge ============ diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 0d2785ce03..d22a8f3e11 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -116,6 +116,12 @@ surf_cpu_t sg_host_surfcpu(sg_host_t host) { void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { xbt_lib_set(host_lib, host->key, SURF_CPU_LEVEL, cpu); } +void sg_host_surfcpu_register(sg_host_t host, surf_cpu_t cpu) +{ + surf_callback_emit(cpuCreatedCallbacks, cpu); + surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, cpu->getState()); + sg_host_surfcpu_set(host, cpu); +} void sg_host_surfcpu_destroy(sg_host_t host) { xbt_lib_unset(host_lib,host->key,SURF_CPU_LEVEL,1); } diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 4d9ae260da..a4579f2a64 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -114,10 +114,7 @@ Cpu *CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak, xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core); cpu = new CpuCas01(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties); - surf_callback_emit(cpuCreatedCallbacks, cpu); - surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, state_initial); - sg_host_surfcpu_set(host, cpu); - + sg_host_surfcpu_register(host, cpu); return cpu; } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 9052b30819..976a85c2d9 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -442,9 +442,7 @@ Cpu *CpuTiModel::createCpu(const char *name, "Power has to be >0.0. Did you forget to specify the mandatory power attribute?"); CpuTi *cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace, core, stateInitial, stateTrace, cpuProperties); - surf_callback_emit(cpuCreatedCallbacks, cpu); - surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, stateInitial); - sg_host_surfcpu_set(host, cpu); + sg_host_surfcpu_register(host, cpu); return cpu; } diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 2f1006a9bb..4209f00c24 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -327,10 +327,7 @@ Cpu *CpuL07Model::createCpu(const char *name, xbt_dynar_t powerPeak, CpuL07 *cpu = new CpuL07(this, name, cpu_properties, power_initial, power_scale, power_trace, core, state_initial, state_trace); - surf_callback_emit(cpuCreatedCallbacks, cpu); - surf_callback_emit(cpuStateChangedCallbacks, cpu, SURF_RESOURCE_ON, state_initial); - sg_host_surfcpu_set(sg_host, cpu); - + sg_host_surfcpu_register(sg_host, cpu); return cpu; } -- 2.20.1