1 /* Copyright (c) 2007-2019. 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 "simgrid/Exception.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
11 #include "smx_private.hpp"
12 #include "src/kernel/activity/IoImpl.hpp"
13 #include "src/mc/mc_replay.hpp"
14 #include "src/simix/smx_io_private.hpp"
15 #include "src/surf/StorageImpl.hpp"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
19 void simcall_HANDLER_io_wait(smx_simcall_t simcall, smx_activity_t synchro)
21 XBT_DEBUG("Wait for execution of synchro %p, state %d", synchro.get(), (int)synchro->state_);
23 /* Associate this simcall to the synchro */
24 synchro->simcalls_.push_back(simcall);
25 simcall->issuer->waiting_synchro = synchro;
27 /* set surf's synchro */
28 if (MC_is_active() || MC_record_replay_is_active()) {
29 synchro->state_ = SIMIX_DONE;
30 SIMIX_io_finish(synchro);
34 /* If the synchro is already finished then perform the error handling */
35 if (synchro->state_ != SIMIX_RUNNING)
36 SIMIX_io_finish(synchro);
39 void SIMIX_io_finish(smx_activity_t synchro)
41 for (smx_simcall_t const& simcall : synchro->simcalls_) {
42 switch (synchro->state_) {
44 /* do nothing, synchro done */
47 simcall->issuer->exception_ =
48 std::make_exception_ptr(simgrid::StorageFailureException(XBT_THROW_POINT, "Storage failed"));
51 simcall->issuer->exception_ =
52 std::make_exception_ptr(simgrid::CancelException(XBT_THROW_POINT, "I/O Canceled"));
55 xbt_die("Internal error in SIMIX_io_finish: unexpected synchro state %d", static_cast<int>(synchro->state_));
58 simcall->issuer->waiting_synchro = nullptr;
59 if (simcall->issuer->get_host()->is_on())
60 SIMIX_simcall_answer(simcall);
62 simcall->issuer->context_->iwannadie = true;