Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function: MSG_parallel_task_execute_with_timeout
[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   if (timeoutDetector)
25     timeoutDetector->unref();
26 }
27 void simgrid::kernel::activity::Exec::suspend()
28 {
29   if (surf_exec)
30     surf_exec->suspend();
31 }
32
33 void simgrid::kernel::activity::Exec::resume()
34 {
35   if (surf_exec)
36     surf_exec->resume();
37 }
38
39 double simgrid::kernel::activity::Exec::remains()
40 {
41   if (state == SIMIX_RUNNING)
42     return surf_exec->getRemains();
43
44   return 0;
45 }
46
47 void simgrid::kernel::activity::Exec::post()
48 {
49   if (host && host->isOff()) {/* FIMXE: handle resource failure for parallel tasks too */
50     /* If the host running the synchro failed, notice it. This way, the asking
51      * process can be killed if it runs on that host itself */
52     state = SIMIX_FAILED;
53   } else if (surf_exec->getState() == simgrid::surf::Action::State::failed) {
54     /* If the host running the synchro didn't fail, then the synchro was canceled */
55     state = SIMIX_CANCELED;
56   } else if (timeoutDetector && timeoutDetector->getState() == simgrid::surf::Action::State::done) {
57     state = SIMIX_TIMEOUT;
58   } else {
59     state = SIMIX_DONE;
60   }
61
62   if (surf_exec) {
63     surf_exec->unref();
64     surf_exec = nullptr;
65   }
66   if (timeoutDetector) {
67     timeoutDetector->unref();
68     timeoutDetector = nullptr;
69   }
70
71   /* If there are simcalls associated with the synchro, then answer them */
72   if (!simcalls.empty())
73     SIMIX_execution_finish(this);
74 }