Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memleak
[simgrid.git] / src / surf / cpu_ti.cpp
index 545f2ba..2be282c 100644 (file)
@@ -380,11 +380,11 @@ int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
  *************/
 
 static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
-  ((CpuTiModelPtr)surf_cpu_model)->parseInit(host);
+  ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host);
 }
 
 static void add_traces_cpu_ti(){
-  surf_cpu_model->addTraces();
+  surf_cpu_model_pm->addTraces();
 }
 
 static void cpu_ti_define_callbacks()
@@ -399,17 +399,17 @@ static void cpu_ti_define_callbacks()
 
 void surf_cpu_model_init_ti()
 {
-  xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
-  surf_cpu_model = new CpuTiModel();
+  xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
+  surf_cpu_model_pm = new CpuTiModel();
   cpu_ti_define_callbacks();
-  ModelPtr model = static_cast<ModelPtr>(surf_cpu_model);
+  ModelPtr model = static_cast<ModelPtr>(surf_cpu_model_pm);
   xbt_dynar_push(model_list, &model);
 }
 
 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
 {
-  xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
-  ActionPtr action;
+  xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
+  ActionPtr action = NULL;
   CpuTi cpu;
 
   cpu_ti_running_action_set_that_does_not_need_being_checked =
@@ -429,16 +429,7 @@ CpuTiModel::~CpuTiModel()
   xbt_lib_cursor_t cursor;
   char *key;
 
-  xbt_lib_foreach(host_lib, cursor, key, cpu){
-    if(cpu[SURF_CPU_LEVEL])
-    {
-        CpuTiPtr CPU = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(cpu[SURF_CPU_LEVEL]));
-        xbt_swag_free(CPU->p_actionSet);
-        delete CPU->p_availTrace;
-    }
-  }
-
-  surf_cpu_model = NULL;
+  surf_cpu_model_pm = NULL;
 
   xbt_swag_free
       (cpu_ti_running_action_set_that_does_not_need_being_checked);
@@ -470,9 +461,6 @@ CpuTiPtr CpuTiModel::createResource(const char *name,
                            tmgr_trace_t stateTrace,
                            xbt_dict_t cpuProperties)
 {
-  tmgr_trace_t empty_trace;
-  s_tmgr_event_t val;
-  CpuTiActionPtr cpuAction;
   xbt_assert(core==1,"Multi-core not handled with this model yet");
   xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
               "Host '%s' declared several times in the platform file",
@@ -483,7 +471,7 @@ CpuTiPtr CpuTiModel::createResource(const char *name,
   return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
 }
 
-CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
+CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
 {
   return NULL;//new CpuTiAction(this, cost, failed);
 }
@@ -506,7 +494,7 @@ double CpuTiModel::shareResources(double now)
   return min_action_duration;
 }
 
-void CpuTiModel::updateActionsState(double now, double delta)
+void CpuTiModel::updateActionsState(double now, double /*delta*/)
 {
   while ((xbt_heap_size(cpu_ti_action_heap) > 0)
          && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
@@ -586,6 +574,7 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
         e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
        xbt_dict_t properties) :
        Resource(model, name, properties), Cpu(model, name, properties) {
+  p_powerEvent = NULL;
   p_stateCurrent = stateInitial;
   m_powerScale = powerScale;
   m_core = core;
@@ -595,9 +584,11 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
   XBT_DEBUG("power scale %lf", powerScale);
   p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
 
-  CpuTiActionPtr action;
+  CpuTiActionPtr action = NULL;
   p_actionSet = xbt_swag_new(xbt_swag_offset(*action, p_cpuListHookup));
 
+  m_lastUpdate = 0;
+
   xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
   xbt_dynar_free(&powerPeak);  /* kill memory leak */
   m_pstate = pstate;
@@ -621,6 +612,11 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
   }
 };
 
+CpuTi::~CpuTi(){
+delete p_availTrace;
+xbt_swag_free(p_actionSet);
+}
+
 void CpuTi::updateState(tmgr_trace_event_t event_type,
                         double value, double date)
 {
@@ -701,7 +697,7 @@ updateRemainingAmount(now);
     action = static_cast<CpuTiActionPtr>(_action);
     /* action not running, skip it */
     if (action->p_stateSet !=
-        surf_cpu_model->p_runningActionSet)
+        surf_cpu_model_pm->p_runningActionSet)
       continue;
 
     /* bogus priority, skip it */
@@ -721,7 +717,7 @@ updateRemainingAmount(now);
     min_finish = -1;
     /* action not running, skip it */
     if (action->p_stateSet !=
-        surf_cpu_model->p_runningActionSet)
+        surf_cpu_model_pm->p_runningActionSet)
       continue;
 
     /* verify if the action is really running on cpu */
@@ -998,9 +994,5 @@ double CpuTiAction::getRemains()
   return m_remains;
 }
 
-static void check() {
-  CpuTiActionPtr cupAction = new CpuTiAction(NULL, 0, true);
-}
-
 #endif /* SURF_MODEL_CPUTI_H_ */