Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5e052a790472f6c8419baa1cd55bd70cb25b90ed
[simgrid.git] / src / surf / model.c
1
2 /* Copyright (c) 2009 The SimGrid Team. All rights reserved.                */
3
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. */
6
7 #include "surf_private.h"
8 #include "xbt/dict.h"
9
10 static void void_die_impossible_paction(surf_action_t action)
11 {
12   DIE_IMPOSSIBLE;
13 }
14
15 static int int_die_impossible_paction(surf_action_t action)
16 {
17   DIE_IMPOSSIBLE;
18 }
19
20 /** @brief initialize common datastructures to all models */
21 void surf_model_init(surf_model_t model)
22 {
23   s_surf_action_t action;
24
25
26   model->model_private = xbt_new0(s_surf_model_private_t, 1);
27
28   model->states.ready_action_set =
29     xbt_swag_new(xbt_swag_offset(action, state_hookup));
30   model->states.running_action_set =
31     xbt_swag_new(xbt_swag_offset(action, state_hookup));
32   model->states.failed_action_set =
33     xbt_swag_new(xbt_swag_offset(action, state_hookup));
34   model->states.done_action_set =
35     xbt_swag_new(xbt_swag_offset(action, state_hookup));
36   model->resource_set = xbt_dict_new();
37
38   model->action_free = int_die_impossible_paction;
39   model->action_cancel = void_die_impossible_paction;
40   model->action_recycle = void_die_impossible_paction;
41
42 }
43
44 void *surf_model_resource_by_name(surf_model_t model, const char *name)
45 {
46   return xbt_dict_get_or_null(model->resource_set, name);
47 }
48
49
50 /** @brief finalize common datastructures to all models */
51 void surf_model_exit(surf_model_t model)
52 {
53   xbt_swag_free(model->states.ready_action_set);
54   xbt_swag_free(model->states.running_action_set);
55   xbt_swag_free(model->states.failed_action_set);
56   xbt_swag_free(model->states.done_action_set);
57   xbt_dict_free(&model->resource_set);
58   free(model->model_private);
59 }