Logo AND Algorithmique Numérique Distribuée

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