Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allow remote exec: s4u::Exec->setHost()
[simgrid.git] / src / s4u / s4u_exec.cpp
1 /* Copyright (c) 2006-2017. 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 #include "xbt/log.h"
6
7 #include "simgrid/s4u/Actor.hpp"
8 #include "simgrid/s4u/Exec.hpp"
9 #include "src/kernel/activity/ExecImpl.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous executions");
12
13 namespace simgrid {
14 namespace s4u {
15
16 void Exec::start()
17 {
18   pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0., host_);
19   state_ = started;
20 }
21
22 void Exec::wait()
23 {
24   simcall_execution_wait(pimpl_);
25 }
26
27 void Exec::wait(double timeout)
28 {
29   THROW_UNIMPLEMENTED;
30 }
31
32 bool Exec::test()
33 {
34   xbt_assert(state_ == inited || state_ == started || state_ == finished);
35
36   if (state_ == finished) {
37     return true;
38   }
39
40   if (state_ == inited) {
41     this->start();
42   }
43
44   return false;
45 }
46
47 ExecPtr Exec::setPriority(double priority)
48 {
49   priority_ = priority;
50   return this;
51 }
52 ExecPtr Exec::setHost(Host* host)
53 {
54   host_ = host;
55   return this;
56 }
57
58 double Exec::getRemains()
59 {
60   return simgrid::simix::kernelImmediate(
61       [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
62 }
63 double Exec::getRemainingRatio()
64 {
65   return simgrid::simix::kernelImmediate(
66       [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remainingRatio(); });
67 }
68
69 void intrusive_ptr_release(simgrid::s4u::Exec* e)
70 {
71   if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
72     std::atomic_thread_fence(std::memory_order_acquire);
73     delete e;
74   }
75 }
76
77 void intrusive_ptr_add_ref(simgrid::s4u::Exec* e)
78 {
79   e->refcount_.fetch_add(1, std::memory_order_relaxed);
80 }
81 }
82 }