Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a std::unique_ptr.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 5 Jan 2020 16:49:10 +0000 (17:49 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 5 Jan 2020 17:32:43 +0000 (18:32 +0100)
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/ExecImpl.hpp

index 43739e7..e5204d7 100644 (file)
@@ -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<s4u::Host*>& 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();
 }
index 67478fb..fe4b94a 100644 (file)
@@ -15,13 +15,13 @@ namespace kernel {
 namespace activity {
 
 class XBT_PUBLIC ExecImpl : public ActivityImpl_T<ExecImpl> {
-  resource::Action* timeout_detector_ = nullptr;
+  std::unique_ptr<resource::Action, std::function<void(resource::Action*)>> timeout_detector_{
+      nullptr, [](resource::Action* a) { a->unref(); }};
   double sharing_penalty_             = 1.0;
   double bound_                       = 0.0;
   std::vector<s4u::Host*> hosts_;
   std::vector<double> flops_amounts_;
   std::vector<double> bytes_amounts_;
-  ~ExecImpl();
 
 public:
   ExecImpl& set_timeout(double timeout);