1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include <xbt/sysdep.h>
10 #include "simgrid/s4u/Host.hpp"
11 #include "simgrid/s4u/Storage.hpp"
12 #include "src/surf/FileImpl.hpp"
13 #include "src/surf/HostImpl.hpp"
14 #include "src/surf/StorageImpl.hpp"
15 #include "surf/surf.h"
17 #include "src/surf/surf_interface.hpp"
18 #include "smx_private.h"
20 #include "src/kernel/activity/SynchroIo.hpp"
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
25 void simcall_HANDLER_file_read(smx_simcall_t simcall, surf_file_t fd, sg_size_t size, sg_host_t host)
27 smx_activity_t synchro = SIMIX_file_read(fd, size, host);
28 synchro->simcalls.push_back(simcall);
29 simcall->issuer->waiting_synchro = synchro;
32 smx_activity_t SIMIX_file_read(surf_file_t file, sg_size_t size, sg_host_t host)
34 /* check if the host is active */
36 THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->getCname());
38 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
40 synchro->surf_io = host->pimpl_->read(file, size);
42 synchro->surf_io->setData(synchro);
43 XBT_DEBUG("Create io synchro %p", synchro);
49 void simcall_HANDLER_file_write(smx_simcall_t simcall, surf_file_t fd, sg_size_t size, sg_host_t host)
51 smx_activity_t synchro = SIMIX_file_write(fd, size, host);
52 synchro->simcalls.push_back(simcall);
53 simcall->issuer->waiting_synchro = synchro;
56 smx_activity_t SIMIX_file_write(surf_file_t file, sg_size_t size, sg_host_t host)
59 THROWF(host_error, 0, "Host %s failed, you cannot call this function", host->getCname());
61 simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
63 synchro->surf_io = host->pimpl_->write(file, size);
64 synchro->surf_io->setData(synchro);
65 XBT_DEBUG("Create io synchro %p", synchro);
70 void SIMIX_io_destroy(smx_activity_t synchro)
72 simgrid::kernel::activity::IoImplPtr io = boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(synchro);
73 XBT_DEBUG("Destroy synchro %p", synchro.get());
78 void SIMIX_io_finish(smx_activity_t synchro)
80 for (smx_simcall_t simcall : synchro->simcalls) {
81 switch (synchro->state) {
83 /* do nothing, synchro done */
86 SMX_EXCEPTION(simcall->issuer, io_error, 0, "IO failed");
89 SMX_EXCEPTION(simcall->issuer, cancel_error, 0, "Canceled");
92 xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state));
95 if (simcall->issuer->host->isOff()) {
96 simcall->issuer->context->iwannadie = 1;
99 simcall->issuer->waiting_synchro = nullptr;
100 SIMIX_simcall_answer(simcall);
103 /* We no longer need it */
104 SIMIX_io_destroy(synchro);