Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement a constructor for surf_action_t; draft a surf_action_maxmin_t for actions...
[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,int failed) {
24   surf_action_t action = xbt_malloc0(size);
25   action->refcount = 1;
26   action->cost = cost;
27   action->remains = cost;
28   action->priority = 1.0;
29   action->max_duration = NO_MAX_DURATION;
30   action->start = surf_get_clock();
31   action->finish = -1.0;
32   action->model_type = model;
33
34   if (failed)
35     action->state_set = model->states.failed_action_set;
36   else
37     action->state_set = model->states.running_action_set;
38
39   xbt_swag_insert(action, action->state_set);
40
41   return action;
42 }
43
44 e_surf_action_state_t surf_action_state_get(surf_action_t action)
45 {
46   surf_action_state_t action_state = &(action->model_type->states);
47
48   if (action->state_set == action_state->ready_action_set)
49     return SURF_ACTION_READY;
50   if (action->state_set == action_state->running_action_set)
51     return SURF_ACTION_RUNNING;
52   if (action->state_set == action_state->failed_action_set)
53     return SURF_ACTION_FAILED;
54   if (action->state_set == action_state->done_action_set)
55     return SURF_ACTION_DONE;
56   return SURF_ACTION_NOT_IN_THE_SYSTEM;
57 }
58
59 double surf_action_get_start_time(surf_action_t action)
60 {
61   return action->start;
62 }
63
64 double surf_action_get_finish_time(surf_action_t action)
65 {
66   return action->finish;
67 }
68
69 void surf_action_free(surf_action_t * action)
70 {
71   (*action)->model_type->action_cancel(*action);
72   free(*action);
73   *action = NULL;
74 }
75
76 void surf_action_state_set(surf_action_t action,
77                               e_surf_action_state_t state)
78 {
79   surf_action_state_t action_state = &(action->model_type->states);
80   XBT_IN2("(%p,%s)", action, surf_action_state_names[state]);
81   xbt_swag_remove(action, action->state_set);
82
83   if (state == SURF_ACTION_READY)
84     action->state_set = action_state->ready_action_set;
85   else if (state == SURF_ACTION_RUNNING)
86     action->state_set = action_state->running_action_set;
87   else if (state == SURF_ACTION_FAILED)
88     action->state_set = action_state->failed_action_set;
89   else if (state == SURF_ACTION_DONE)
90     action->state_set = action_state->done_action_set;
91   else
92     action->state_set = NULL;
93
94   if (action->state_set)
95     xbt_swag_insert(action, action->state_set);
96   XBT_OUT;
97 }
98
99 void surf_action_data_set(surf_action_t action, void *data)
100 {
101   action->data = data;
102 }
103
104 void surf_action_ref(surf_action_t action)
105 {
106   action->refcount++;
107 }
108 /*
109 void surf_action_suspend(surf_action_t action)
110 {
111   action->suspended = 1;
112 }*/
113
114 /*
115  * Maxmin action
116  */