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;
38 action->state_set = model->states.failed_action_set;
40 action->state_set = model->states.running_action_set;
42 xbt_swag_insert(action, action->state_set);
47 e_surf_action_state_t surf_action_state_get(surf_action_t action)
49 surf_action_state_t action_state = &(action->model_type->states);
51 if (action->state_set == action_state->ready_action_set)
52 return SURF_ACTION_READY;
53 if (action->state_set == action_state->running_action_set)
54 return SURF_ACTION_RUNNING;
55 if (action->state_set == action_state->failed_action_set)
56 return SURF_ACTION_FAILED;
57 if (action->state_set == action_state->done_action_set)
58 return SURF_ACTION_DONE;
59 return SURF_ACTION_NOT_IN_THE_SYSTEM;
62 double surf_action_get_start_time(surf_action_t action)
67 double surf_action_get_finish_time(surf_action_t action)
69 /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
70 return action->remains == 0 ? action->finish : -1;
73 XBT_INLINE void surf_action_free(surf_action_t * action)
75 (*action)->model_type->action_cancel(*action);
80 void surf_action_state_set(surf_action_t action, e_surf_action_state_t state)
82 surf_action_state_t action_state = &(action->model_type->states);
83 XBT_IN2("(%p,%s)", action, surf_action_state_names[state]);
84 xbt_swag_remove(action, action->state_set);
86 if (state == SURF_ACTION_READY)
87 action->state_set = action_state->ready_action_set;
88 else if (state == SURF_ACTION_RUNNING)
89 action->state_set = action_state->running_action_set;
90 else if (state == SURF_ACTION_FAILED)
91 action->state_set = action_state->failed_action_set;
92 else if (state == SURF_ACTION_DONE)
93 action->state_set = action_state->done_action_set;
95 action->state_set = NULL;
97 if (action->state_set)
98 xbt_swag_insert(action, action->state_set);
102 void surf_action_data_set(surf_action_t action, void *data)
107 XBT_INLINE void surf_action_ref(surf_action_t action)
113 void surf_action_suspend(surf_action_t action)
115 action->suspended = 1;