Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] Factorize some CPU registration code in sg_host_surfcpu_register() (DRY)
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 24 Nov 2015 11:54:26 +0000 (12:54 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 24 Nov 2015 11:54:39 +0000 (12:54 +0100)
include/simgrid/host.h
src/simgrid/host.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/host_ptask_L07.cpp

index b422c4f..c6fb943 100644 (file)
@@ -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 ============
index 0d2785c..d22a8f3 100644 (file)
@@ -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);
 }
index 4d9ae26..a4579f2 100644 (file)
@@ -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;
 }
 
index 9052b30..976a85c 100644 (file)
@@ -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;
 }
 
index 2f1006a..4209f00 100644 (file)
@@ -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;
 }