Logo AND Algorithmique Numérique Distribuée

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