Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5528f864faf292e8d5ba36cb55851e82d5607a9a
[simgrid.git] / src / kernel / activity / SynchroExec.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/SynchroExec.hpp"
9 #include "src/surf/surf_interface.hpp"
10 #include "src/simix/smx_host_private.h"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process);
13
14 simgrid::kernel::activity::Exec::Exec(const char*name, sg_host_t host) :
15     host_(host)
16 {
17   if (name)
18     this->name = name;
19   this->state = SIMIX_RUNNING;
20 }
21
22 simgrid::kernel::activity::Exec::~Exec()
23 {
24   if (surf_exec)
25     surf_exec->unref();
26   if (timeoutDetector)
27     timeoutDetector->unref();
28 }
29 void simgrid::kernel::activity::Exec::suspend()
30 {
31   XBT_VERB("This exec is suspended (remain: %f)", surf_exec->getRemains());
32   if (surf_exec)
33     surf_exec->suspend();
34 }
35
36 void simgrid::kernel::activity::Exec::resume()
37 {
38   XBT_VERB("This exec is resumed (remain: %f)", surf_exec->getRemains());
39   if (surf_exec)
40     surf_exec->resume();
41 }
42
43 double simgrid::kernel::activity::Exec::remains()
44 {
45   if (state == SIMIX_RUNNING)
46     return surf_exec->getRemains();
47
48   return 0;
49 }
50
51 void simgrid::kernel::activity::Exec::post()
52 {
53   if (host_ && host_->isOff()) {/* FIXME: handle resource failure for parallel tasks too */
54     /* If the host running the synchro failed, notice it. This way, the asking
55      * process can be killed if it runs on that host itself */
56     state = SIMIX_FAILED;
57   } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
58     /* If the host running the synchro didn't fail, then the synchro was canceled */
59     state = SIMIX_CANCELED;
60   } else if (timeoutDetector && timeoutDetector->getState() == simgrid::surf::Action::State::done) {
61     state = SIMIX_TIMEOUT;
62   } else {
63     state = SIMIX_DONE;
64   }
65
66   if (surf_exec) {
67     surf_exec->unref();
68     surf_exec = nullptr;
69   }
70   if (timeoutDetector) {
71     timeoutDetector->unref();
72     timeoutDetector = nullptr;
73   }
74
75   /* If there are simcalls associated with the synchro, then answer them */
76   if (!simcalls.empty())
77     SIMIX_execution_finish(this);
78 }