Logo AND Algorithmique Numérique Distribuée

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