Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
be sure the Exec is assigned before getting its host
[simgrid.git] / src / s4u / s4u_Exec.cpp
index ae4367f75fb80e40179162fb4719e59c68fd4fb7..e6723c4383a90b4ad592a51fffa1db84bacff749 100644 (file)
@@ -17,17 +17,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous execut
 namespace simgrid {
 namespace s4u {
 xbt::signal<void(Exec const&)> Exec::on_start;
-xbt::signal<void(Exec const&)> Exec::on_completion;
 
 Exec::Exec(kernel::activity::ExecImplPtr pimpl)
 {
   pimpl_ = pimpl;
 }
 
-void Exec::complete(Activity::State state)
+void Exec::reset() const
 {
-  Activity::complete(state);
-  on_completion(*this);
+  boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->reset();
 }
 
 ExecPtr Exec::init()
@@ -41,7 +39,7 @@ ExecPtr Exec::init()
     }
   });
   pimpl->set_cb_id(cb_id);
-  return ExecPtr(pimpl->get_iface());
+  return ExecPtr(static_cast<Exec*>(pimpl->get_iface()));
 }
 
 Exec* Exec::start()
@@ -161,16 +159,6 @@ 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). */
@@ -208,6 +196,22 @@ ExecPtr Exec::set_hosts(const std::vector<Host*>& hosts)
   return this;
 }
 
+ExecPtr Exec::unset_host()
+{
+  if (not is_assigned())
+    throw std::invalid_argument(
+        xbt::string_printf("Exec %s: the activity is not assigned to any host(s)", get_cname()));
+  else {
+    reset();
+
+    if (state_ == State::STARTED)
+      cancel();
+    vetoable_start();
+
+    return this;
+  }
+}
+
 double Exec::get_cost() const
 {
   return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_cost();