Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
protect against multiply create hosts in one location only
[simgrid.git] / src / surf / cpu_ti.cpp
index 160fa74..b2242fa 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014. The SimGrid Team.
+/* Copyright (c) 2013-2015. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -381,7 +381,6 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
 
 static void cpu_ti_define_callbacks()
 {
-  sg_platf_host_add_cb(cpu_parse_init);
   sg_platf_postparse_add_cb(cpu_add_traces);
 }
 
@@ -400,11 +399,11 @@ void surf_cpu_model_init_ti()
   cpu_ti_define_callbacks();
   Model *model_pm = static_cast<Model*>(surf_cpu_model_pm);
   Model *model_vm = static_cast<Model*>(surf_cpu_model_vm);
-  xbt_dynar_push(model_list, &model_pm);
-  xbt_dynar_push(model_list, &model_vm);
+  xbt_dynar_push(all_existing_models, &model_pm);
+  xbt_dynar_push(all_existing_models, &model_vm);
 }
 
-CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
+CpuTiModel::CpuTiModel() : CpuModel()
 {
   p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
 
@@ -435,14 +434,11 @@ Cpu *CpuTiModel::createCpu(const char *name,
 {
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   sg_host_t host = sg_host_by_name(name);
-  xbt_assert(!sg_host_surfcpu(host),
-              "Host '%s' declared several times in the platform file",
-              name);
   xbt_assert(xbt_dynar_getfirst_as(powerPeak, double) > 0.0,
       "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);
-  sg_host_surfcpu_set(host, cpu);
+  sg_host_surfcpu_register(host, cpu);
   return cpu;
 }
 
@@ -545,11 +541,10 @@ void CpuTiModel::addTraces()
 CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t powerPeak,
         int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
-       xbt_dict_t properties)
-: Cpu(model, name, properties, core, 0, powerScale)
+             xbt_dict_t properties)
+  : Cpu(model, name, properties, core, 0, powerScale, stateInitial)
 {
   p_powerEvent = NULL;
-  setState(stateInitial);
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;
@@ -563,7 +558,6 @@ CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t powerPeak,
   m_lastUpdate = 0;
 
   xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
-  xbt_dynar_free(&powerPeak);  /* kill memory leak */
   XBT_DEBUG("CPU create: peak=%f", m_powerPeak);
 
   if (stateTrace)
@@ -836,11 +830,11 @@ CpuAction *CpuTi::sleep(double duration)
 void CpuTi::modified(bool modified){
   CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
   if (modified) {
-    if (!is_linked()) {
+    if (!cpu_ti_hook.is_linked()) {
       modifiedCpu->push_back(*this);
     }
   } else {
-    if (is_linked()) {
+    if (cpu_ti_hook.is_linked()) {
       modifiedCpu->erase(modifiedCpu->iterator_to(*this));
     }
   }
@@ -881,10 +875,10 @@ int CpuTiAction::unref()
 {
   m_refcount--;
   if (!m_refcount) {
-       if (actionHook::is_linked())
+       if (action_hook.is_linked())
          getStateSet()->erase(getStateSet()->iterator_to(*this));
     /* remove from action_set */
-    if (actionTiHook::is_linked())
+    if (action_ti_hook.is_linked())
       p_cpu->p_actionSet->erase(p_cpu->p_actionSet->iterator_to(*this));
     /* remove from heap */
     xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, this->m_indexHeap);
@@ -903,11 +897,6 @@ void CpuTiAction::cancel()
   return;
 }
 
-void CpuTiAction::recycle()
-{
-  DIE_IMPOSSIBLE;
-}
-
 void CpuTiAction::suspend()
 {
   XBT_IN("(%p)", this);