1 /* Copyright (c) 2007-2018. 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. */
6 #include "src/kernel/activity/SleepImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/resource/Action.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/kernel/context/Context.hpp"
12 #include "simgrid/Exception.hpp"
13 #include "src/simix/ActorImpl.hpp"
14 #include "src/simix/popping_private.hpp"
15 #include "src/simix/smx_private.hpp"
16 #include "src/surf/surf_interface.hpp"
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
20 void simgrid::kernel::activity::SleepImpl::suspend()
22 surf_sleep->suspend();
25 void simgrid::kernel::activity::SleepImpl::resume()
30 void simgrid::kernel::activity::SleepImpl::post()
32 while (not simcalls_.empty()) {
33 smx_simcall_t simcall = simcalls_.front();
34 simcalls_.pop_front();
36 if (host && host->is_off()) {
37 /* If the host running the synchro failed, notice it. This way, the asking
38 * actor can be killed if it runs on that host itself */
39 result = SIMIX_SRC_HOST_FAILURE;
40 simcall->issuer->throw_exception(
41 std::make_exception_ptr(simgrid::HostFailureException(XBT_THROW_POINT, "Host failed")));
44 switch (surf_sleep->get_state()) {
45 case simgrid::kernel::resource::Action::State::FAILED:
46 simcall->issuer->context_->iwannadie = 1;
47 result = SIMIX_FAILED;
50 case simgrid::kernel::resource::Action::State::FINISHED:
58 if (simcall->issuer->host_->is_off()) {
59 simcall->issuer->context_->iwannadie = 1;
61 simcall_process_sleep__set__result(simcall, result);
62 simcall->issuer->waiting_synchro = nullptr;
63 if (simcall->issuer->suspended_) {
64 XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
65 simcall->issuer->suspended_ = 0;
66 simcall_HANDLER_process_suspend(simcall, simcall->issuer);
68 SIMIX_simcall_answer(simcall);
72 SIMIX_process_sleep_destroy(this);