Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename variable hiding class field.
[simgrid.git] / src / kernel / activity / SleepImpl.cpp
1 /* Copyright (c) 2007-2017. 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 "src/kernel/activity/SleepImpl.hpp"
9 #include "src/kernel/context/Context.hpp"
10
11 #include "src/simix/ActorImpl.hpp"
12 #include "src/simix/popping_private.hpp"
13 #include "src/surf/surf_interface.hpp"
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
16
17 void simgrid::kernel::activity::SleepImpl::suspend()
18 {
19   surf_sleep->suspend();
20 }
21
22 void simgrid::kernel::activity::SleepImpl::resume()
23 {
24   surf_sleep->resume();
25 }
26
27 void simgrid::kernel::activity::SleepImpl::post()
28 {
29   while (not simcalls.empty()) {
30     smx_simcall_t simcall = simcalls.front();
31     simcalls.pop_front();
32
33     e_smx_state_t result;
34     switch (surf_sleep->getState()) {
35       case simgrid::surf::Action::State::failed:
36         simcall->issuer->context->iwannadie = 1;
37         result                              = SIMIX_SRC_HOST_FAILURE;
38         break;
39
40       case simgrid::surf::Action::State::done:
41         result = SIMIX_DONE;
42         break;
43
44       default:
45         THROW_IMPOSSIBLE;
46         break;
47     }
48     if (simcall->issuer->host->isOff()) {
49       simcall->issuer->context->iwannadie = 1;
50     }
51     simcall_process_sleep__set__result(simcall, result);
52     simcall->issuer->waiting_synchro = nullptr;
53     if (simcall->issuer->suspended) {
54       XBT_DEBUG("Wait! This process is suspended and can't wake up now.");
55       simcall->issuer->suspended = 0;
56       simcall_HANDLER_process_suspend(simcall, simcall->issuer);
57     } else {
58       SIMIX_simcall_answer(simcall);
59     }
60   }
61
62   SIMIX_process_sleep_destroy(this);
63 }