Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add more callbacks
[simgrid.git] / src / surf / cpu_ti.cpp
index b7e0362..c1c35e5 100644 (file)
@@ -408,11 +408,9 @@ void surf_cpu_model_init_ti()
 
 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
 {
-  ActionPtr action = NULL;
   CpuTiPtr cpu = NULL;
 
-  p_runningActionSetThatDoesNotNeedBeingChecked =
-      xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
+  p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
 
   p_modifiedCpu =
       xbt_swag_new(xbt_swag_offset(*cpu, p_modifiedCpuHookup));
@@ -426,7 +424,7 @@ CpuTiModel::~CpuTiModel()
 {
   surf_cpu_model_pm = NULL;
 
-  xbt_swag_free(p_runningActionSetThatDoesNotNeedBeingChecked);
+  delete p_runningActionSetThatDoesNotNeedBeingChecked;
   xbt_swag_free(p_modifiedCpu);
   xbt_heap_free(p_tiActionHeap);
 }
@@ -532,7 +530,7 @@ void CpuTiModel::addTraces()
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
-    CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
+    CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
 
     xbt_assert(cpu, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
@@ -566,10 +564,10 @@ CpuTi::CpuTi(CpuTiModelPtr 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)
-: Resource(model, name, properties)
-, Cpu(core, 0, powerScale) {
+: Cpu(model, name, properties, core, 0, powerScale)
+{
   p_powerEvent = NULL;
-  m_stateCurrent = stateInitial;
+  setState(stateInitial);
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;            
@@ -645,11 +643,11 @@ void CpuTi::updateState(tmgr_trace_event_t event_type,
 
   } else if (event_type == p_stateEvent) {
     if (value > 0) {
-      if(m_stateCurrent == SURF_RESOURCE_OFF)
+      if(getState() == SURF_RESOURCE_OFF)
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     } else {
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
 
       /* put all action running on cpu to failed */
       xbt_swag_foreach(_action, p_actionSet) {
@@ -824,7 +822,7 @@ void CpuTi::updateRemainingAmount(double now)
 CpuActionPtr CpuTi::execute(double size)
 {
   XBT_IN("(%s,%g)", getName(), size);
-  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, m_stateCurrent != SURF_RESOURCE_ON, this);
+  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
 
   xbt_swag_insert(action, p_actionSet);
 
@@ -839,16 +837,16 @@ CpuActionPtr CpuTi::sleep(double duration)
     duration = MAX(duration, MAXMIN_PRECISION);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, m_stateCurrent != SURF_RESOURCE_ON, this);
+  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
 
   action->m_maxDuration = duration;
   action->m_suspended = 2;
   if (duration == NO_MAX_DURATION) {
    /* Move to the *end* of the corresponding action set. This convention
       is used to speed up update_resource_state  */
-    xbt_swag_remove(static_cast<ActionPtr>(action), action->getStateSet());
+       action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
     action->p_stateSet = reinterpret_cast<CpuTiModelPtr>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
-    xbt_swag_insert(static_cast<ActionPtr>(action), action->getStateSet());
+    action->getStateSet()->push_back(*static_cast<ActionPtr>(action));
   }
 
   xbt_swag_insert(action, p_actionSet);
@@ -868,8 +866,7 @@ static void cpu_ti_action_update_index_heap(void *action, int i)
 
 CpuTiAction::CpuTiAction(CpuTiModelPtr model_, double cost, bool failed,
                                 CpuTiPtr cpu)
- : Action(model_, cost, failed)
- , CpuAction(model_, cost, failed)
+ : CpuAction(model_, cost, failed)
 {
   p_cpuListHookup.next = 0;
   p_cpuListHookup.prev = 0;
@@ -896,7 +893,8 @@ int CpuTiAction::unref()
 {
   m_refcount--;
   if (!m_refcount) {
-    xbt_swag_remove(static_cast<ActionPtr>(this), getStateSet());
+       if (actionHook::is_linked())
+         getStateSet()->erase(getStateSet()->iterator_to(*this));
     /* remove from action_set */
     xbt_swag_remove(this, p_cpu->p_actionSet);
     /* remove from heap */