Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize some code in SURF
[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
9 static void void_die_impossible_paction(surf_action_t action) {
10         DIE_IMPOSSIBLE;
11 }
12 static int int_die_impossible_paction(surf_action_t action) {
13         DIE_IMPOSSIBLE;
14 }
15
16 /** @brief initialize common datastructures to all models */
17 void surf_model_init(surf_model_t model) {
18           s_surf_action_t action;
19
20
21           model->common_private = xbt_new0(s_surf_model_private_t, 1);
22
23           model->common_public.states.ready_action_set =
24             xbt_swag_new(xbt_swag_offset(action, state_hookup));
25           model->common_public.states.running_action_set =
26             xbt_swag_new(xbt_swag_offset(action, state_hookup));
27           model->common_public.states.failed_action_set =
28             xbt_swag_new(xbt_swag_offset(action, state_hookup));
29           model->common_public.states.done_action_set =
30             xbt_swag_new(xbt_swag_offset(action, state_hookup));
31
32           model->common_public.action_free = int_die_impossible_paction;
33           model->common_public.action_cancel = void_die_impossible_paction;
34           model->common_public.action_recycle = void_die_impossible_paction;
35
36 }
37
38
39 /** @brief finalize common datastructures to all models */
40 void surf_model_exit(surf_model_t model) {
41           xbt_swag_free(model->common_public.states.ready_action_set);
42           xbt_swag_free(model->common_public.states.running_action_set);
43           xbt_swag_free(model->common_public.states.failed_action_set);
44           xbt_swag_free(model->common_public.states.done_action_set);
45           free(model->common_private);
46 }