Logo AND Algorithmique Numérique Distribuée

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