Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please clang
[simgrid.git] / include / simgrid / s4u / Exec.hpp
1 /* Copyright (c) 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
6 #ifndef SIMGRID_S4U_EXEC_HPP
7 #define SIMGRID_S4U_EXEC_HPP
8
9 #include "src/kernel/activity/ExecImpl.hpp"
10 #include <simgrid/forward.h>
11 #include <simgrid/s4u/forward.hpp>
12
13 namespace simgrid {
14 namespace s4u {
15
16 XBT_PUBLIC_CLASS Exec : public Activity
17 {
18   Exec() : Activity() {}
19 public:
20   friend void intrusive_ptr_release(simgrid::s4u::Exec * e)
21   {
22     if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
23       std::atomic_thread_fence(std::memory_order_acquire);
24       delete e;
25     }
26   }
27
28   friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e) { e->refcount_.fetch_add(1, std::memory_order_relaxed); }
29
30   friend Actor; // Factory of Exec
31
32   ~Exec() = default;
33
34   void start() override
35   {
36     pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
37     state_ = started;
38   }
39   void wait() override { this->wait(-1); }
40   void wait(double timeout) override { simcall_execution_wait(pimpl_); }
41
42   double getRemains()
43   {
44     return simgrid::simix::kernelImmediate(
45         [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
46   }
47
48 private:
49   smx_actor_t runner_  = nullptr;
50   double flops_amount_ = 0.0;
51   double priority_     = 1.0;
52   double bound_        = 0.0;
53
54   std::atomic_int_fast32_t refcount_{0};
55 }; // class
56 }
57 }; // Namespace simgrid::s4u
58
59 #endif /* SIMGRID_S4U_EXEC_HPP */