Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sleep activities throw exception on host failure
[simgrid.git] / src / kernel / activity / SleepImpl.cpp
1 /* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u/Host.hpp"
7
8 #include "simgrid/kernel/resource/Action.hpp"
9 #include "src/kernel/activity/SleepImpl.hpp"
10 #include "src/kernel/context/Context.hpp"
11
12 #include "src/simix/ActorImpl.hpp"
13 #include "src/simix/popping_private.hpp"
14 #include "src/simix/smx_private.hpp"
15 #include "src/surf/surf_interface.hpp"
16 #include "xbt/ex.hpp"
17
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
19
20 void simgrid::kernel::activity::SleepImpl::suspend()
21 {
22   surf_sleep->suspend();
23 }
24
25 void simgrid::kernel::activity::SleepImpl::resume()
26 {
27   surf_sleep->resume();
28 }
29
30 void simgrid::kernel::activity::SleepImpl::post()
31 {
32   while (not simcalls_.empty()) {
33     smx_simcall_t simcall = simcalls_.front();
34     simcalls_.pop_front();
35     e_smx_state_t result;
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       SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
41     }
42
43     switch (surf_sleep->get_state()) {
44       case simgrid::kernel::resource::Action::State::FAILED:
45         simcall->issuer->context_->iwannadie = 1;
46         result                               = SIMIX_FAILED;
47         break;
48
49       case simgrid::kernel::resource::Action::State::FINISHED:
50         result = SIMIX_DONE;
51         break;
52
53       default:
54         THROW_IMPOSSIBLE;
55         break;
56     }
57     if (simcall->issuer->host_->is_off()) {
58       simcall->issuer->context_->iwannadie = 1;
59     }
60     simcall_process_sleep__set__result(simcall, result);
61     simcall->issuer->waiting_synchro = nullptr;
62     if (simcall->issuer->suspended_) {
63       XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
64       simcall->issuer->suspended_ = 0;
65       simcall_HANDLER_process_suspend(simcall, simcall->issuer);
66     } else {
67       SIMIX_simcall_answer(simcall);
68     }
69   }
70
71   SIMIX_process_sleep_destroy(this);
72 }