From 356f981b289325c49f2a4fe6e788705dba0b047c Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sun, 5 Jan 2020 17:49:10 +0100 Subject: [PATCH] Use a std::unique_ptr. --- src/kernel/activity/ExecImpl.cpp | 16 ++-------------- src/kernel/activity/ExecImpl.hpp | 4 ++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 43739e7688..e5204d77f4 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -99,13 +99,6 @@ namespace simgrid { namespace kernel { namespace activity { -ExecImpl::~ExecImpl() -{ - if (timeout_detector_) - timeout_detector_->unref(); - XBT_DEBUG("Destroy exec %p", this); -} - ExecImpl& ExecImpl::set_host(s4u::Host* host) { if (not hosts_.empty()) @@ -123,7 +116,7 @@ ExecImpl& ExecImpl::set_hosts(const std::vector& hosts) ExecImpl& ExecImpl::set_timeout(double timeout) { if (timeout > 0 && not MC_is_active() && not MC_record_replay_is_active()) { - timeout_detector_ = hosts_.front()->pimpl_cpu->sleep(timeout); + timeout_detector_.reset(hosts_.front()->pimpl_cpu->sleep(timeout)); timeout_detector_->set_activity(this); } return *this; @@ -210,12 +203,7 @@ void ExecImpl::post() } clean_action(); - - if (timeout_detector_) { - timeout_detector_->unref(); - timeout_detector_ = nullptr; - } - + timeout_detector_.reset(); /* Answer all simcalls associated with the synchro */ finish(); } diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index 67478fbaf0..fe4b94a120 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -15,13 +15,13 @@ namespace kernel { namespace activity { class XBT_PUBLIC ExecImpl : public ActivityImpl_T { - resource::Action* timeout_detector_ = nullptr; + std::unique_ptr> timeout_detector_{ + nullptr, [](resource::Action* a) { a->unref(); }}; double sharing_penalty_ = 1.0; double bound_ = 0.0; std::vector hosts_; std::vector flops_amounts_; std::vector bytes_amounts_; - ~ExecImpl(); public: ExecImpl& set_timeout(double timeout); -- 2.30.2