Logo AND Algorithmique Numérique Distribuée

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