1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 #include "smx_private.h"
8 #include "xbt/sysdep.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix,
14 "Logging specific to SIMIX (io)");
16 void SIMIX_pre_file_read(smx_req_t req)
18 smx_action_t action = SIMIX_file_read(req->issuer, req->file_read.name);
19 xbt_fifo_push(action->request_list, req);
20 req->issuer->waiting_action = action;
23 smx_action_t SIMIX_file_read(smx_process_t process, char* name)
26 smx_host_t host = process->smx_host;
28 /* check if the host is active */
29 if (surf_workstation_model->extension.
30 workstation.get_state(host->host) != SURF_RESOURCE_ON) {
31 THROWF(host_error, 0, "Host %s failed, you cannot call this function",
35 action = xbt_mallocator_get(simix_global->action_mallocator);
36 action->type = SIMIX_ACTION_IO;
39 action->category = NULL;
42 action->io.host = host;
43 // TODO in surf model disk???
44 // action->io.surf_io = surf_workstation_model->extension.disk.read(host->host, name),
45 action->io.surf_io = surf_workstation_model->extension.workstation.sleep(host->host, 1.0);
47 surf_workstation_model->action_data_set(action->io.surf_io, action);
48 XBT_DEBUG("Create io action %p", action);
53 void SIMIX_post_io(smx_action_t action)
55 switch (surf_workstation_model->action_state_get(action->io.surf_io)) {
57 case SURF_ACTION_FAILED:
58 action->state = SIMIX_FAILED;
61 case SURF_ACTION_DONE:
62 action->state = SIMIX_DONE;
70 SIMIX_io_finish(action);
73 void SIMIX_io_destroy(smx_action_t action)
75 XBT_DEBUG("Destroy action %p", action);
76 if (action->io.surf_io)
77 action->io.surf_io->model_type->action_unref(action->io.surf_io);
78 xbt_mallocator_release(simix_global->action_mallocator, action);
81 void SIMIX_io_finish(smx_action_t action)
83 volatile xbt_fifo_item_t item;
86 xbt_fifo_foreach(action->request_list, item, req, smx_req_t) {
88 switch (action->state) {
91 /* do nothing, action done */
96 THROWF(io_error, 0, "IO failed");
98 CATCH(req->issuer->running_ctx->exception) {
99 req->issuer->doexception = 1;
105 THROWF(cancel_error, 0, "Canceled");
107 CATCH(req->issuer->running_ctx->exception) {
108 req->issuer->doexception = 1;
113 xbt_die("Internal error in SIMIX_io_finish: unexpected action state %d",
116 req->issuer->waiting_action = NULL;
117 SIMIX_request_answer(req);
120 /* We no longer need it */
121 SIMIX_io_destroy(action);