1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "surf_private.h"
9 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
15 const char *surf_action_state_names[6] = {
17 "SURF_ACTION_RUNNING",
20 "SURF_ACTION_TO_FREE",
21 "SURF_ACTION_NOT_IN_THE_SYSTEM"
24 void *surf_action_new(size_t size, double cost, surf_model_t model,
27 surf_action_t action = xbt_malloc0(size);
30 action->remains = cost;
31 action->priority = 1.0;
32 action->max_duration = NO_MAX_DURATION;
33 action->start = surf_get_clock();
34 action->finish = -1.0;
35 action->model_type = model;
37 action->category = NULL;
41 action->state_set = model->states.failed_action_set;
43 action->state_set = model->states.running_action_set;
45 xbt_swag_insert(action, action->state_set);
50 e_surf_action_state_t surf_action_state_get(surf_action_t action)
52 surf_action_state_t action_state = &(action->model_type->states);
54 if (action->state_set == action_state->ready_action_set)
55 return SURF_ACTION_READY;
56 if (action->state_set == action_state->running_action_set)
57 return SURF_ACTION_RUNNING;
58 if (action->state_set == action_state->failed_action_set)
59 return SURF_ACTION_FAILED;
60 if (action->state_set == action_state->done_action_set)
61 return SURF_ACTION_DONE;
62 return SURF_ACTION_NOT_IN_THE_SYSTEM;
65 double surf_action_get_start_time(surf_action_t action)
70 double surf_action_get_finish_time(surf_action_t action)
72 /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
73 return action->remains == 0 ? action->finish : -1;
76 XBT_INLINE void surf_action_free(surf_action_t * action)
78 (*action)->model_type->action_cancel(*action);
83 void surf_action_state_set(surf_action_t action,
84 e_surf_action_state_t state)
86 surf_action_state_t action_state = &(action->model_type->states);
87 XBT_IN2("(%p,%s)", action, surf_action_state_names[state]);
88 xbt_swag_remove(action, action->state_set);
90 if (state == SURF_ACTION_READY)
91 action->state_set = action_state->ready_action_set;
92 else if (state == SURF_ACTION_RUNNING)
93 action->state_set = action_state->running_action_set;
94 else if (state == SURF_ACTION_FAILED)
95 action->state_set = action_state->failed_action_set;
96 else if (state == SURF_ACTION_DONE)
97 action->state_set = action_state->done_action_set;
99 action->state_set = NULL;
101 if (action->state_set)
102 xbt_swag_insert(action, action->state_set);
106 void surf_action_data_set(surf_action_t action, void *data)
111 XBT_INLINE void surf_action_ref(surf_action_t action)
117 void surf_action_suspend(surf_action_t action)
119 action->suspended = 1;