1 /* Authors: Arnaud Legrand */
3 /* This program is free software; you can redistribute it and/or modify it
4 under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "surf_private.h"
8 static xbt_heap_float_t NOW=0;
10 xbt_dynar_t resource_list = NULL;
11 tmgr_history_t history = NULL;
12 lmm_system_t maxmin_system = NULL;
14 e_surf_action_state_t surf_action_get_state(surf_action_t action)
16 surf_action_state_t action_state = &(action->resource_type->states);
18 if(action->state_set == action_state->ready_action_set)
19 return SURF_ACTION_READY;
20 if(action->state_set == action_state->running_action_set)
21 return SURF_ACTION_RUNNING;
22 if(action->state_set == action_state->failed_action_set)
23 return SURF_ACTION_FAILED;
24 if(action->state_set == action_state->done_action_set)
25 return SURF_ACTION_DONE;
26 return SURF_ACTION_NOT_IN_THE_SYSTEM;
29 void surf_action_free(surf_action_t * action)
31 (*action)->resource_type->action_cancel(*action);
36 void surf_action_change_state(surf_action_t action, e_surf_action_state_t state)
38 surf_action_state_t action_state = &(action->resource_type->states);
40 xbt_swag_remove(action, action->state_set);
42 if(state == SURF_ACTION_READY)
43 action->state_set = action_state->ready_action_set;
44 else if(state == SURF_ACTION_RUNNING)
45 action->state_set = action_state->running_action_set;
46 else if(state == SURF_ACTION_FAILED)
47 action->state_set = action_state->failed_action_set;
48 else if(state == SURF_ACTION_DONE)
49 action->state_set = action_state->done_action_set;
50 else action->state_set = NULL;
52 if(action->state_set) xbt_swag_insert(action, action->state_set);
57 if(!resource_list) resource_list = xbt_dynar_new(sizeof(surf_resource_t), NULL);
58 if(!history) history = tmgr_history_new();
59 if(!maxmin_system) maxmin_system = lmm_system_new();
62 xbt_heap_float_t surf_solve(void)
64 xbt_heap_float_t min = -1.0;
65 xbt_heap_float_t next_event_date = -1.0;
66 xbt_heap_float_t resource_next_action_end = -1.0;
67 xbt_maxmin_float_t value = -1.0;
68 surf_resource_t resource = NULL;
71 xbt_dynar_foreach (resource_list,i,resource) {
72 resource_next_action_end = resource->share_resources(NOW);
73 if((min<0) || (resource_next_action_end<min))
74 min = resource_next_action_end;
77 while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
78 if(next_event_date > NOW+min) break;
79 while (tmgr_history_get_next_event_leq(history, next_event_date,
80 &value, (void **) &resource)) {
81 if(surf_cpu_resource->resource.resource_used(resource)) {
82 min = next_event_date-NOW;
87 xbt_dynar_foreach (resource_list,i,resource) {
88 resource->update_state(NOW, min);
96 xbt_heap_float_t surf_get_clock(void)