+ surf_action_cpu_t action = NULL;
+ surf_action_cpu_t next_action = NULL;
+ xbt_swag_t running_actions =
+ surf_cpu_resource->common_public->states.running_action_set;
+ xbt_swag_t failed_actions =
+ surf_cpu_resource->common_public->states.failed_action_set;
+
+ xbt_swag_foreach_safe(action, next_action, running_actions) {
+ action->generic_action.remains -=
+ lmm_variable_getvalue(action->variable) * delta;
+ if (action->generic_action.max_duration != NO_MAX_DURATION)
+ action->generic_action.max_duration -= delta;
+/* if(action->generic_action.remains<.00001) action->generic_action.remains=0; */
+ if ((action->generic_action.remains <= 0) &&
+ (lmm_get_variable_weight(action->variable)>0)) {
+ action->generic_action.finish = surf_get_clock();
+ action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+ } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
+ (action->generic_action.max_duration <= 0)) {
+ action->generic_action.finish = surf_get_clock();
+ action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+ } else { /* Need to check that none of the resource has failed */
+ lmm_constraint_t cnst = NULL;
+ int i = 0;
+ cpu_t cpu = NULL;
+
+ while ((cnst =
+ lmm_get_cnst_from_var(maxmin_system, action->variable,
+ i++))) {
+ cpu = lmm_constraint_id(cnst);
+ if (cpu->state_current == SURF_CPU_OFF) {
+ action->generic_action.finish = surf_get_clock();
+ action_change_state((surf_action_t) action, SURF_ACTION_FAILED);
+ break;
+ }
+ }
+ }
+ }
+
+ xbt_swag_foreach_safe(action, next_action, failed_actions) {
+ lmm_variable_disable(maxmin_system, action->variable);
+ }
+
+ return;
+}
+
+static void update_resource_state(void *id,
+ tmgr_trace_event_t event_type,
+ double value)
+{
+ cpu_t cpu = id;
+
+/* printf("[" "%lg" "] Asking to update CPU \"%s\" with value " */
+/* "%lg" " for event %p\n", surf_get_clock(), cpu->name, */
+/* value, event_type); */
+
+ if (event_type == cpu->power_event) {
+ cpu->power_current = value;
+ lmm_update_constraint_bound(maxmin_system, cpu->constraint,
+ cpu->power_current * cpu->power_scale);
+ } else if (event_type == cpu->state_event) {
+ if (value > 0)
+ cpu->state_current = SURF_CPU_ON;
+ else
+ cpu->state_current = SURF_CPU_OFF;
+ } else {
+ CRITICAL0("Unknown event ! \n");
+ xbt_abort();
+ }
+