Logo AND Algorithmique Numérique Distribuée

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