Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
properly split init/start for Exec activities
[simgrid.git] / include / simgrid / s4u / Exec.hpp
1 /* Copyright (c) 2017-2019. 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 <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11
12 #include <atomic>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** Computation Activity, representing the asynchronous executions.
18  *
19  * They are generated from simgrid::s4u::this_actor::exec_init() or simgrid::s4u::Host::execute(),
20  * and can be used to model pools of threads or similar mechanisms.
21  */
22
23 class XBT_PUBLIC Exec : public Activity {
24   explicit Exec(sg_host_t host, double flops_amount);
25
26 public:
27   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Exec * e);
28   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Exec * e);
29   friend XBT_PUBLIC ExecPtr this_actor::exec_init(double flops_amount);
30
31   ~Exec() = default;
32
33   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_start;
34   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_completion;
35
36   Exec* start() override;
37   Exec* wait() override;
38   Exec* wait_for(double timeout) override;
39   Exec* cancel() override;
40   bool test() override;
41
42   ExecPtr set_priority(double priority);
43   ExecPtr set_bound(double bound);
44   ExecPtr set_host(Host* host);
45   ExecPtr set_name(std::string name);
46   ExecPtr set_tracing_category(std::string category);
47   Host* get_host();
48
49   double get_remaining() override;
50   double get_remaining_ratio();
51
52 #ifndef DOXYGEN
53   //////////////// Deprecated functions
54   XBT_ATTRIB_DEPRECATED_v324("Please use Exec::wait_for()") void wait(double t) override { wait_for(t); }
55   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_priority()") ExecPtr setPriority(double priority)
56   {
57     return set_priority(priority);
58   }
59   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_bound()") ExecPtr setBound(double bound) { return set_bound(bound); }
60   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_host()") ExecPtr setHost(Host* host) { return set_host(host); }
61   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_host()") Host* getHost() { return get_host(); }
62   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_remaining_ratio()") double getRemainingRatio()
63   {
64     return get_remaining_ratio();
65   }
66 #endif
67
68 private:
69   Host* host_                   = nullptr;
70   double flops_amount_          = 0.0;
71   double priority_              = 1.0;
72   double bound_                 = 0.0;
73   std::string name_             = "";
74   std::string tracing_category_ = "";
75   std::atomic_int_fast32_t refcount_{0};
76 }; // class
77 }
78 }; // Namespace simgrid::s4u
79
80 #endif /* SIMGRID_S4U_EXEC_HPP */