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 / SynchroExec.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 <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 simgrid::kernel::activity::Exec::Exec(const char*name, sg_host_t hostarg)
13 {
14   if (name)
15     this->name = name;
16   this->state = SIMIX_RUNNING;
17   this->host = hostarg;
18 }
19
20 simgrid::kernel::activity::Exec::~Exec()
21 {
22   if (surf_exec)
23     surf_exec->unref();
24 }
25 void simgrid::kernel::activity::Exec::suspend()
26 {
27   if (surf_exec)
28     surf_exec->suspend();
29 }
30
31 void simgrid::kernel::activity::Exec::resume()
32 {
33   if (surf_exec)
34     surf_exec->resume();
35 }
36
37 double simgrid::kernel::activity::Exec::remains()
38 {
39   if (state == SIMIX_RUNNING)
40     return surf_exec->getRemains();
41
42   return 0;
43 }
44
45 void simgrid::kernel::activity::Exec::post()
46 {
47   if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */
48     /* If the host running the synchro failed, notice it. This way, the asking
49      * process can be killed if it runs on that host itself */
50     state = SIMIX_FAILED;
51   } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
52     /* If the host running the synchro didn't fail, then the synchro was canceled */
53     state = SIMIX_CANCELED;
54   } else {
55     state = SIMIX_DONE;
56   }
57
58   if (surf_exec) {
59     surf_exec->unref();
60     surf_exec = nullptr;
61   }
62
63   /* If there are simcalls associated with the synchro, then answer them */
64   if (!simcalls.empty())
65     SIMIX_execution_finish(this);
66 }