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,int failed) {
24 surf_action_t action = xbt_malloc0(size);
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;
35 action->state_set = model->states.failed_action_set;
37 action->state_set = model->states.running_action_set;
39 xbt_swag_insert(action, action->state_set);
44 e_surf_action_state_t surf_action_state_get(surf_action_t action)
46 surf_action_state_t action_state = &(action->model_type->states);
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;
59 double surf_action_get_start_time(surf_action_t action)
64 double surf_action_get_finish_time(surf_action_t action)
66 return action->finish;
69 void surf_action_free(surf_action_t * action)
71 (*action)->model_type->action_cancel(*action);
76 void surf_action_state_set(surf_action_t action,
77 e_surf_action_state_t state)
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);
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;
92 action->state_set = NULL;
94 if (action->state_set)
95 xbt_swag_insert(action, action->state_set);
99 void surf_action_data_set(surf_action_t action, void *data)
104 void surf_action_ref(surf_action_t action)
109 void surf_action_suspend(surf_action_t action)
111 action->suspended = 1;