XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_timer, surf,
"Logging specific to SURF (timer)");
+typedef struct surf_action_timer {
+ s_surf_action_t generic_action;
+} s_surf_action_timer_t, *surf_action_timer_t;
+
typedef struct command {
- s_surf_resource_t generic_resource; /* Must remain first, since we add this to a trace */
+ s_surf_resource_t generic_resource; /* Must remain first, since we add this to a trace */
void *function;
void *args;
s_xbt_swag_hookup_t command_set_hookup;
+ surf_action_timer_t action;
} s_command_t, *command_t;
command->function = fun;
command->args = args;
xbt_swag_insert(command, command_pending);
+ command->action =
+ surf_action_new(sizeof(s_surf_action_timer_t), 0, surf_timer_model, 0);
return command;
}
} else if (xbt_swag_belongs(command, command_pending)) {
xbt_swag_remove(command, command_pending);
}
- surf_resource_free((surf_resource_t)command);
+ xbt_swag_remove(command->action,
+ surf_timer_model->states.running_action_set);
+ xbt_free(command->action);
+ surf_resource_free((surf_resource_t) command);
return;
}
return 1;
}
-static void action_change_state(surf_action_t action,
- e_surf_action_state_t state)
+static void timer_action_state_set(surf_action_t action,
+ e_surf_action_state_t state)
{
DIE_IMPOSSIBLE;
return;
static double share_resources(double now)
{
- if (xbt_heap_size(timer_heap))
+ if (xbt_heap_size(timer_heap)) {
+ DEBUG1("Share resoure returning %lf", xbt_heap_maxkey(timer_heap));
return (xbt_heap_maxkey(timer_heap));
- else
+ } else
return -1.0;
}
static void update_actions_state(double now, double delta)
{
- if (xbt_heap_size(timer_heap)) {
- if (xbt_heap_maxkey(timer_heap) <= now + delta) {
- xbt_heap_pop(timer_heap);
- }
- }
+ while ((xbt_heap_size(timer_heap)) > 0
+ && (xbt_heap_maxkey(timer_heap) <= now + delta))
+ xbt_heap_pop(timer_heap);
return;
}
/* Move this command to the list of commands to execute */
xbt_swag_remove(command, command_pending);
xbt_swag_insert(command, command_to_run);
+ tmgr_trace_event_free(event_type);
+
+ DEBUG1("Insert command on date %lf", date);
return;
}
tmgr_history_add_trace(history, empty_trace, date, 0, command);
xbt_heap_push(timer_heap, NULL, date);
+
+ DEBUG1("Putting value %lf on heap", date);
}
if (command) {
*function = command->function;
*arg = command->args;
+ command_free(command);
return 1;
} else {
return 0;
{
surf_timer_model = surf_model_init();
- surf_timer_model->action_get_state = surf_action_get_state;
- surf_timer_model->action_change_state = action_change_state;
- surf_timer_model->action_set_data = surf_action_set_data;
surf_timer_model->name = "TIMER";
+ surf_timer_model->action_state_set = timer_action_state_set;
surf_timer_model->model_private->resource_used = resource_used;
surf_timer_model->model_private->share_resources = share_resources;