1 /* Copyright (c) 2007-2010, 2012-2014. The SimGrid Team.
2 * 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 /* ****************************************************************************************** */
8 /* TUTORIAL: New API */
9 /* ****************************************************************************************** */
10 #include "smx_private.h"
11 #include "xbt/sysdep.h"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_new_api, simix,
17 "Logging specific to SIMIX (new_api)");
20 //SIMIX NEW MODEL INIT
21 void SIMIX_pre_new_api_fct(smx_simcall_t simcall)
23 smx_action_t action = SIMIX_new_api_fct(simcall->issuer,
24 simcall->new_api.param1,
25 simcall->new_api.param2);
26 xbt_fifo_push(action->simcalls, simcall);
27 simcall->issuer->waiting_action = action;
30 void SIMIX_post_new_api(smx_action_t action)
33 smx_simcall_t simcall;
35 xbt_fifo_foreach(action->simcalls,i,simcall,smx_simcall_t) {
36 switch (simcall->call) {
37 case SIMCALL_NEW_API_INIT:
38 simcall->new_api.result = 0;
46 switch (surf_action_get_state(action->new_api.surf_new_api)) {
48 case SURF_ACTION_FAILED:
49 action->state = SIMIX_FAILED;
52 case SURF_ACTION_DONE:
53 action->state = SIMIX_DONE;
61 SIMIX_new_api_finish(action);
64 smx_action_t SIMIX_new_api_fct(smx_process_t process, const char* param1, double param2)
67 smx_host_t host = process->smx_host;
69 /* check if the host is active */
70 if (surf_resource_get_state(surf_workstation_resource_priv(host)) != SURF_RESOURCE_ON) {
71 THROWF(host_error, 0, "Host %s failed, you cannot call this function",
75 action = xbt_mallocator_get(simix_global->action_mallocator);
76 action->type = SIMIX_ACTION_NEW_API;
79 action->category = NULL;
82 // Called the function from the new model
83 //FIXME:CHECK WHAT TO DO action->new_api.surf_new_api = surf_workstation_model->extension.new_model.fct();
85 surf_action_set_data(action->new_api.surf_new_api, action);
86 XBT_DEBUG("Create NEW MODEL action %p", action);
91 void SIMIX_new_api_destroy(smx_action_t action)
93 XBT_DEBUG("Destroy action %p", action);
94 if (action->new_api.surf_new_api)
95 surf_action_unref(action->new_api.surf_new_api);
96 xbt_mallocator_release(simix_global->action_mallocator, action);
99 void SIMIX_new_api_finish(smx_action_t action)
101 xbt_fifo_item_t item;
102 smx_simcall_t simcall;
104 xbt_fifo_foreach(action->simcalls, item, simcall, smx_simcall_t) {
106 switch (action->state) {
109 /* do nothing, action done */
113 SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
117 SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
121 xbt_die("Internal error in SIMIX_NEW_MODEL_finish: unexpected action state %d",
125 if (surf_resource_get_state(surf_workstation_resource_priv(simcall->issuer->smx_host)) != SURF_RESOURCE_ON) {
126 simcall->issuer->context->iwannadie = 1;
129 simcall->issuer->waiting_action = NULL;
130 SIMIX_simcall_answer(simcall);
133 /* We no longer need it */
134 SIMIX_new_api_destroy(action);