Logo AND Algorithmique Numérique Distribuée

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