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:
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
* Resource *
************/
class DiskImpl : public Resource, public xbt::PropertyHolder {
- bool currently_destroying_ = false;
s4u::Host* host_ = nullptr;
s4u::Disk piface_;
double read_bw_;
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_; }
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_);
*/
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)
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;
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
* @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