Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CommWaitTransition mailbox is now valid
[simgrid.git] / src / s4u / s4u_Exec.cpp
index 4efdc11290c7383d3c7074da427497943e995e96..14f8e74dcf08e21a013898b4acdfa81cb6f127f6 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -23,7 +23,7 @@ Exec::Exec(kernel::activity::ExecImplPtr pimpl)
   pimpl_ = pimpl;
 }
 
-void Exec::reset()
+void Exec::reset() const
 {
   boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->reset();
 }
@@ -32,9 +32,9 @@ ExecPtr Exec::init()
 {
   auto pimpl = kernel::activity::ExecImplPtr(new kernel::activity::ExecImpl());
   unsigned int cb_id = Host::on_state_change.connect([pimpl](s4u::Host const& h) {
-    if (not h.is_on() && pimpl->state_ == kernel::activity::State::RUNNING &&
+    if (not h.is_on() && pimpl->get_state() == kernel::activity::State::RUNNING &&
         std::find(pimpl->get_hosts().begin(), pimpl->get_hosts().end(), &h) != pimpl->get_hosts().end()) {
-      pimpl->state_ = kernel::activity::State::FAILED;
+      pimpl->set_state(kernel::activity::State::FAILED);
       pimpl->post();
     }
   });
@@ -61,20 +61,10 @@ Exec* Exec::start()
 
 ssize_t Exec::wait_any_for(const std::vector<ExecPtr>& execs, double timeout)
 {
-  std::vector<kernel::activity::ExecImpl*> rexecs(execs.size());
-  std::transform(begin(execs), end(execs), begin(rexecs),
-                 [](const ExecPtr& exec) { return static_cast<kernel::activity::ExecImpl*>(exec->pimpl_.get()); });
-
-  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
-  kernel::actor::ExecutionWaitanySimcall observer{issuer, rexecs, timeout};
-  ssize_t changed_pos = kernel::actor::simcall_blocking(
-      [&observer] {
-        kernel::activity::ExecImpl::wait_any_for(observer.get_issuer(), observer.get_execs(), observer.get_timeout());
-      },
-      &observer);
-  if (changed_pos != -1)
-    execs.at(changed_pos)->complete(State::FINISHED);
-  return changed_pos;
+  std::vector<ActivityPtr> activities;
+  for (const auto& exec : execs)
+    activities.push_back(boost::dynamic_pointer_cast<Activity>(exec));
+  return Activity::wait_any_for(activities, timeout);
 }
 
 /** @brief change the execution bound
@@ -159,16 +149,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). */