From: Arnaud Giersch Date: Mon, 3 May 2021 12:30:53 +0000 (+0200) Subject: Move fields from Exec to ExecImpl. X-Git-Tag: v3.28~374 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0ef63aae64c3c35f3c9b6bc8da2c610048aa56ba Move fields from Exec to ExecImpl. The Exec may be released before the end of the execution, bringing a null dereference when finish_time is set. --- diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index ac5b5f6c53..ee5be7eb18 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -32,8 +32,6 @@ namespace s4u { class XBT_PUBLIC Exec : public Activity_T { 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; diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 9810d0d3e3..3553841d57 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -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(); diff --git a/src/kernel/activity/ExecImpl.hpp b/src/kernel/activity/ExecImpl.hpp index 6bfc5941e6..cdfd3e8d68 100644 --- a/src/kernel/activity/ExecImpl.hpp +++ b/src/kernel/activity/ExecImpl.hpp @@ -21,6 +21,8 @@ class XBT_PUBLIC ExecImpl : public ActivityImpl_T { 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 hosts_; std::vector flops_amounts_; std::vector 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(); } diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 2ae3ad2f2d..5e71c09679 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -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(pimpl_.get())->get_host_number(); } +double Exec::get_start_time() const +{ + return static_cast(pimpl_.get())->get_start_time(); +} + +double Exec::get_finish_time() const +{ + return static_cast(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). */