2 /* Copyright (c) 2009 The SimGrid Team. 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"
10 static void void_die_impossible_paction(surf_action_t action) {
13 static int int_die_impossible_paction(surf_action_t action) {
17 /** @brief initialize common datastructures to all models */
18 void surf_model_init(surf_model_t model) {
19 s_surf_action_t action;
22 model->common_private = xbt_new0(s_surf_model_private_t, 1);
24 model->common_public.states.ready_action_set =
25 xbt_swag_new(xbt_swag_offset(action, state_hookup));
26 model->common_public.states.running_action_set =
27 xbt_swag_new(xbt_swag_offset(action, state_hookup));
28 model->common_public.states.failed_action_set =
29 xbt_swag_new(xbt_swag_offset(action, state_hookup));
30 model->common_public.states.done_action_set =
31 xbt_swag_new(xbt_swag_offset(action, state_hookup));
32 model->common_public.resource_set = xbt_dict_new();
34 model->common_public.action_free = int_die_impossible_paction;
35 model->common_public.action_cancel = void_die_impossible_paction;
36 model->common_public.action_recycle = void_die_impossible_paction;
40 void* surf_model_resource_by_name(void* model, const char *name) {
41 return xbt_dict_get_or_null(((surf_model_t)model)->common_public.resource_set,name);
45 /** @brief finalize common datastructures to all models */
46 void surf_model_exit(surf_model_t model) {
47 xbt_swag_free(model->common_public.states.ready_action_set);
48 xbt_swag_free(model->common_public.states.running_action_set);
49 xbt_swag_free(model->common_public.states.failed_action_set);
50 xbt_swag_free(model->common_public.states.done_action_set);
51 xbt_dict_free(&model->common_public.resource_set);
52 free(model->common_private);