1 /* Copyright (c) 2009 The SimGrid Team. All rights reserved. */
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 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
14 const char *surf_action_state_names[6] = {
16 "SURF_ACTION_RUNNING",
19 "SURF_ACTION_TO_FREE",
20 "SURF_ACTION_NOT_IN_THE_SYSTEM"
23 void *surf_action_new(size_t size, double cost, surf_model_t model,
26 surf_action_t action = xbt_malloc0(size);
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;
37 action->state_set = model->states.failed_action_set;
39 action->state_set = model->states.running_action_set;
41 xbt_swag_insert(action, action->state_set);
46 e_surf_action_state_t surf_action_state_get(surf_action_t action)
48 surf_action_state_t action_state = &(action->model_type->states);
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;
61 double surf_action_get_start_time(surf_action_t action)
66 double surf_action_get_finish_time(surf_action_t action)
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;
72 XBT_INLINE void surf_action_free(surf_action_t * action)
74 (*action)->model_type->action_cancel(*action);
79 void surf_action_state_set(surf_action_t action, e_surf_action_state_t state)
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);
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;
94 action->state_set = NULL;
96 if (action->state_set)
97 xbt_swag_insert(action, action->state_set);
101 void surf_action_data_set(surf_action_t action, void *data)
106 XBT_INLINE void surf_action_ref(surf_action_t action)
112 void surf_action_suspend(surf_action_t action)
114 action->suspended = 1;