Logo AND Algorithmique Numérique Distribuée

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