Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix use after free.
[simgrid.git] / src / kernel / resource / StandardLinkImpl.hpp
1 /* Copyright (c) 2004-2022. 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_KERNEL_RESOURCE_STANDARDLINKIMPL_HPP
7 #define SIMGRID_KERNEL_RESOURCE_STANDARDLINKIMPL_HPP
8
9 #include "src/kernel/resource/LinkImpl.hpp"
10
11 /***********
12  * Classes *
13  ***********/
14
15 namespace simgrid {
16 namespace kernel {
17 namespace resource {
18 /************
19  * Resource *
20  ************/
21 class StandardLinkImpl : public LinkImpl {
22   s4u::Link piface_;
23   s4u::Link::SharingPolicy sharing_policy_ = s4u::Link::SharingPolicy::SHARED;
24   routing::NetZoneImpl* englobing_zone_    = nullptr;
25
26 protected:
27   explicit StandardLinkImpl(const std::string& name);
28   StandardLinkImpl(const StandardLinkImpl&) = delete;
29   StandardLinkImpl& operator=(const StandardLinkImpl&) = delete;
30   ~StandardLinkImpl() override                         = default; // Use destroy() instead of this destructor.
31
32   Metric latency_   = {0.0, 1, nullptr};
33   Metric bandwidth_ = {1.0, 1, nullptr};
34
35 public:
36   void destroy(); // Must be called instead of the destructor
37   class Deleter {
38   public:
39     void operator()(StandardLinkImpl* link) const;
40   };
41
42   void latency_check(double latency) const;
43
44   /** @brief Public interface */
45   const s4u::Link* get_iface() const { return &piface_; }
46   s4u::Link* get_iface() { return &piface_; }
47
48   /** @brief Get the bandwidth in bytes per second of current Link */
49   double get_bandwidth() const override { return bandwidth_.peak * bandwidth_.scale; }
50
51   /** @brief Get the latency in seconds of current Link */
52   double get_latency() const override { return latency_.peak * latency_.scale; }
53
54   routing::NetZoneImpl* get_englobing_zone() const { return englobing_zone_; }
55   /** @brief Set the NetZone in which this Link is included */
56   StandardLinkImpl* set_englobing_zone(routing::NetZoneImpl* netzone_p);
57
58   /** @brief The sharing policy */
59   void set_sharing_policy(s4u::Link::SharingPolicy policy, const s4u::NonLinearResourceCb& cb) override;
60   s4u::Link::SharingPolicy get_sharing_policy() const override { return sharing_policy_; }
61
62   void turn_on() override;
63   void turn_off() override;
64
65   void seal() override;
66
67   void on_bandwidth_change() const;
68
69   /* setup the profile file with bandwidth events (peak speed changes due to external load).
70    * Profile must contain percentages (value between 0 and 1). */
71   void set_bandwidth_profile(kernel::profile::Profile* profile) override;
72   /* setup the profile file with latency events (peak latency changes due to external load).
73    * Profile must contain absolute values */
74   void set_latency_profile(kernel::profile::Profile* profile) override;
75
76   void set_concurrency_limit(int limit) const override;
77 };
78
79 } // namespace resource
80 } // namespace kernel
81 } // namespace simgrid
82
83 #endif /* SIMGRID_KERNEL_RESOURCE_STANDARDLINKIMPL_HPP */