Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use access modifier to disallow direct deletion. Remove superfluous boolean.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 23 Feb 2021 18:50:23 +0000 (19:50 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 23 Feb 2021 21:13:47 +0000 (22:13 +0100)
include/simgrid/s4u/Host.hpp
src/kernel/resource/DiskImpl.cpp
src/kernel/resource/DiskImpl.hpp
src/s4u/s4u_Host.cpp
src/surf/disk_s19.hpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp

index b4c98e2..fe1dcc4 100644 (file)
@@ -45,11 +45,8 @@ public:
   explicit Host(const std::string& name);
 
 protected:
-  virtual ~Host();
+  virtual ~Host(); // Call destroy() instead of manually deleting it.
   void set_netpoint(kernel::routing::NetPoint* netpoint) { pimpl_netpoint_ = netpoint; }
-
-private:
-  bool currently_destroying_ = false;
 #endif
 
 public:
index 22245da..f9d1b3a 100644 (file)
@@ -48,22 +48,14 @@ DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kern
   constraint_write_ = maxminSystem->constraint_new(this, write_bw);
 }
 
-DiskImpl::~DiskImpl()
-{
-  xbt_assert(currently_destroying_, "Don't delete Disks directly. Call destroy() instead.");
-}
-
 /** @brief Fire the required callbacks and destroy the object
  *
  * Don't delete directly a Disk, call d->destroy() instead.
  */
 void DiskImpl::destroy()
 {
-  if (not currently_destroying_) {
-    currently_destroying_ = true;
-    s4u::Disk::on_destruction(this->piface_);
-    delete this;
-  }
+  s4u::Disk::on_destruction(this->piface_);
+  delete this;
 }
 
 bool DiskImpl::is_used() const
index 146fb31..2a2d85d 100644 (file)
@@ -48,7 +48,6 @@ public:
  * Resource *
  ************/
 class DiskImpl : public Resource, public xbt::PropertyHolder {
-  bool currently_destroying_ = false;
   s4u::Host* host_           = nullptr;
   s4u::Disk piface_;
   double read_bw_;
@@ -56,13 +55,14 @@ class DiskImpl : public Resource, public xbt::PropertyHolder {
   lmm::Constraint* constraint_write_; /* Constraint for maximum write bandwidth*/
   lmm::Constraint* constraint_read_;  /* Constraint for maximum read bandwidth*/
 
+protected:
+  ~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
+
 public:
   DiskImpl(Model* model, const std::string& name, kernel::lmm::System* maxmin_system, double read_bw, double bwrite_bw);
   DiskImpl(const DiskImpl&) = delete;
   DiskImpl& operator=(const DiskImpl&) = delete;
 
-  ~DiskImpl() override;
-
   /** @brief Public interface */
   const s4u::Disk* get_iface() const { return &piface_; }
   s4u::Disk* get_iface() { return &piface_; }
index f2549c6..becb093 100644 (file)
@@ -39,8 +39,6 @@ Host::Host(const std::string& name) : name_(name)
 
 Host::~Host()
 {
-  xbt_assert(currently_destroying_, "Please call h->destroy() instead of manually deleting it.");
-
   delete pimpl_;
   if (pimpl_netpoint_ != nullptr) // not removed yet by a children class
     Engine::get_instance()->netpoint_unregister(pimpl_netpoint_);
@@ -56,12 +54,9 @@ Host::~Host()
  */
 void Host::destroy()
 {
-  if (not currently_destroying_) {
-    currently_destroying_ = true;
-    on_destruction(*this);
-    Engine::get_instance()->host_unregister(std::string(name_));
-    delete this;
-  }
+  on_destruction(*this);
+  Engine::get_instance()->host_unregister(std::string(name_));
+  delete this;
 }
 
 Host* Host::by_name(const std::string& name)
index 11ea111..a46ffce 100644 (file)
@@ -42,7 +42,6 @@ class DiskS19 : public DiskImpl {
 public:
   DiskS19(DiskModel* model, const std::string& name, kernel::lmm::System* maxminSystem, double read_bw,
           double write_bw);
-  ~DiskS19() override = default;
   DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) override;
   DiskAction* read(sg_size_t size) override;
   DiskAction* write(sg_size_t size) override;
index e1f1ae6..c2f2caa 100644 (file)
@@ -86,22 +86,14 @@ LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint
   XBT_DEBUG("Create link '%s'", name.c_str());
 }
 
-/** @brief use destroy() instead of this destructor */
-LinkImpl::~LinkImpl()
-{
-  xbt_assert(currently_destroying_, "Don't delete Links directly. Call destroy() instead.");
-}
 /** @brief Fire the required callbacks and destroy the object
  *
  * Don't delete directly a Link, call l->destroy() instead.
  */
 void LinkImpl::destroy()
 {
-  if (not currently_destroying_) {
-    currently_destroying_ = true;
-    s4u::Link::on_destruction(this->piface_);
-    delete this;
-  }
+  s4u::Link::on_destruction(this->piface_);
+  delete this;
 }
 
 bool LinkImpl::is_used() const
index 40b6ed7..f092a17 100644 (file)
@@ -108,14 +108,13 @@ public:
  * @details A Link represents the link between two [hosts](@ref simgrid::surf::HostImpl)
  */
 class LinkImpl : public Resource, public xbt::PropertyHolder {
-  bool currently_destroying_ = false;
   s4u::Link piface_;
 
 protected:
   LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint);
   LinkImpl(const LinkImpl&) = delete;
   LinkImpl& operator=(const LinkImpl&) = delete;
-  ~LinkImpl() override;
+  ~LinkImpl() override                 = default; // Use destroy() instead of this destructor.
 
 public:
   void destroy(); // Must be called instead of the destructor