Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed full routing support for routers, no routing complexity is added routers are...
[simgrid.git] / src / surf / surf_action.c
1 /* Copyright (c) 2009 The SimGrid Team. All rights reserved.                */
2
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. */
5
6 #include "surf_private.h"
7
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
9
10 /*
11  * Generic action
12  */
13
14 const char *surf_action_state_names[6] = {
15   "SURF_ACTION_READY",
16   "SURF_ACTION_RUNNING",
17   "SURF_ACTION_FAILED",
18   "SURF_ACTION_DONE",
19   "SURF_ACTION_TO_FREE",
20   "SURF_ACTION_NOT_IN_THE_SYSTEM"
21 };
22
23 void *surf_action_new(size_t size, double cost, surf_model_t model,
24                       int failed)
25 {
26   surf_action_t action = xbt_malloc0(size);
27   action->refcount = 1;
28   action->cost = cost;
29   action->remains = cost;
30   action->priority = 1.0;
31   action->max_duration = NO_MAX_DURATION;
32   action->start = surf_get_clock();
33   action->finish = -1.0;
34   action->model_type = model;
35
36   if (failed)
37     action->state_set = model->states.failed_action_set;
38   else
39     action->state_set = model->states.running_action_set;
40
41   xbt_swag_insert(action, action->state_set);
42
43   return action;
44 }
45
46 e_surf_action_state_t surf_action_state_get(surf_action_t action)
47 {
48   surf_action_state_t action_state = &(action->model_type->states);
49
50   if (action->state_set == action_state->ready_action_set)
51     return SURF_ACTION_READY;
52   if (action->state_set == action_state->running_action_set)
53     return SURF_ACTION_RUNNING;
54   if (action->state_set == action_state->failed_action_set)
55     return SURF_ACTION_FAILED;
56   if (action->state_set == action_state->done_action_set)
57     return SURF_ACTION_DONE;
58   return SURF_ACTION_NOT_IN_THE_SYSTEM;
59 }
60
61 double surf_action_get_start_time(surf_action_t action)
62 {
63   return action->start;
64 }
65
66 double surf_action_get_finish_time(surf_action_t action)
67 {
68   /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
69   return action->remains == 0 ? action->finish : -1;
70 }
71
72 void surf_action_free(surf_action_t * action)
73 {
74   (*action)->model_type->action_cancel(*action);
75   free(*action);
76   *action = NULL;
77 }
78
79 void surf_action_state_set(surf_action_t action, e_surf_action_state_t state)
80 {
81   surf_action_state_t action_state = &(action->model_type->states);
82   XBT_IN2("(%p,%s)", action, surf_action_state_names[state]);
83   xbt_swag_remove(action, action->state_set);
84
85   if (state == SURF_ACTION_READY)
86     action->state_set = action_state->ready_action_set;
87   else if (state == SURF_ACTION_RUNNING)
88     action->state_set = action_state->running_action_set;
89   else if (state == SURF_ACTION_FAILED)
90     action->state_set = action_state->failed_action_set;
91   else if (state == SURF_ACTION_DONE)
92     action->state_set = action_state->done_action_set;
93   else
94     action->state_set = NULL;
95
96   if (action->state_set)
97     xbt_swag_insert(action, action->state_set);
98   XBT_OUT;
99 }
100
101 void surf_action_data_set(surf_action_t action, void *data)
102 {
103   action->data = data;
104 }
105
106 void surf_action_ref(surf_action_t action)
107 {
108   action->refcount++;
109 }
110
111 /*
112 void surf_action_suspend(surf_action_t action)
113 {
114   action->suspended = 1;
115 }*/
116
117 /*
118  * Maxmin action
119  */