Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move fields from Exec to ExecImpl.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 3 May 2021 12:30:53 +0000 (14:30 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 3 May 2021 14:46:14 +0000 (16:46 +0200)
The Exec may be released before the end of the execution, bringing a
null dereference when finish_time is set.

include/simgrid/s4u/Exec.hpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/ExecImpl.hpp
src/s4u/s4u_Exec.cpp

index ac5b5f6..ee5be7e 100644 (file)
@@ -32,8 +32,6 @@ namespace s4u {
 class XBT_PUBLIC Exec : public Activity_T<Exec> {
   friend kernel::activity::ExecImpl;
   bool parallel_ = false;
-  double start_time_ = -1.0;
-  double finish_time_ = -1.0;
 
 protected:
   explicit Exec(kernel::activity::ExecImplPtr pimpl);
@@ -74,9 +72,8 @@ public:
 
   Host* get_host() const;
   unsigned int get_host_number() const;
-  double get_start_time() const { return start_time_; }
-  double get_finish_time() const { return finish_time_; }
-  void set_finish_time(double finish_time) { finish_time_ = finish_time; }
+  double get_start_time() const;
+  double get_finish_time() const;
   double get_cost() const;
   bool is_parallel() const { return parallel_; }
   bool is_assigned() const override;
index 9810d0d..3553841 100644 (file)
@@ -91,6 +91,7 @@ ExecImpl* ExecImpl::start()
       surf_action_    = host_model->execute_parallel(hosts_, flops_amounts_.data(), bytes_amounts_.data(), -1);
     }
     surf_action_->set_activity(this);
+    start_time_ = surf_action_->get_start_time();
   }
 
   XBT_DEBUG("Create execute synchro %p: %s", this, get_cname());
@@ -141,7 +142,7 @@ void ExecImpl::post()
     state_ = State::DONE;
   }
 
-  get_iface()->set_finish_time(surf_action_->get_finish_time());
+  finish_time_ = surf_action_->get_finish_time();
 
   clean_action();
   timeout_detector_.reset();
index 6bfc594..cdfd3e8 100644 (file)
@@ -21,6 +21,8 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl_T<ExecImpl> {
   actor::ActorImpl* actor_            = nullptr;
   double sharing_penalty_             = 1.0;
   double bound_                       = 0.0;
+  double start_time_                  = -1.0;
+  double finish_time_                 = -1.0;
   std::vector<s4u::Host*> hosts_;
   std::vector<double> flops_amounts_;
   std::vector<double> bytes_amounts_;
@@ -34,6 +36,9 @@ public:
   ExecImpl& set_bound(double bound);
   ExecImpl& set_sharing_penalty(double sharing_penalty);
 
+  double get_start_time() const { return start_time_; }
+  double get_finish_time() const { return finish_time_; }
+
   ExecImpl& set_flops_amount(double flop_amount);
   ExecImpl& set_host(s4u::Host* host);
   s4u::Host* get_host() const { return hosts_.front(); }
index 2ae3ad2..5e71c09 100644 (file)
@@ -49,7 +49,6 @@ Exec* Exec::start()
     pimpl_->suspend();
 
   state_      = State::STARTED;
-  start_time_ = pimpl_->surf_action_->get_start_time();
   on_start(*this);
   return this;
 }
@@ -155,6 +154,16 @@ unsigned int Exec::get_host_number() const
   return static_cast<kernel::activity::ExecImpl*>(pimpl_.get())->get_host_number();
 }
 
+double Exec::get_start_time() const
+{
+  return static_cast<kernel::activity::ExecImpl*>(pimpl_.get())->get_start_time();
+}
+
+double Exec::get_finish_time() const
+{
+  return static_cast<kernel::activity::ExecImpl*>(pimpl_.get())->get_finish_time();
+}
+
 /** @brief Change the host on which this activity takes place.
  *
  * The activity cannot be terminated already (but it may be started). */