Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
implement Exec::wait_for()
[simgrid.git] / src / s4u / s4u_Exec.cpp
index 0bee8d4..66016d3 100644 (file)
@@ -39,20 +39,20 @@ bool Exec::test()
 }
 
 Exec* Exec::wait()
+{
+  return this->wait_for(-1);
+}
+
+Exec* Exec::wait_for(double timeout)
 {
   if (state_ == State::INITED)
     start();
-  simcall_execution_wait(pimpl_);
+  simcall_execution_wait(pimpl_, timeout);
   state_ = State::FINISHED;
   on_completion(*Actor::self(), *this);
   return this;
 }
 
-Exec* Exec::wait_for(double)
-{
-  THROW_UNIMPLEMENTED;
-}
-
 int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
 {
   std::unique_ptr<kernel::activity::ExecImpl* []> rexecs(new kernel::activity::ExecImpl*[execs->size()]);
@@ -68,19 +68,6 @@ Exec* Exec::cancel()
   return this;
 }
 
-void intrusive_ptr_release(simgrid::s4u::Exec* e)
-{
-  if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-    std::atomic_thread_fence(std::memory_order_acquire);
-    delete e;
-  }
-}
-
-void intrusive_ptr_add_ref(simgrid::s4u::Exec* e)
-{
-  e->refcount_.fetch_add(1, std::memory_order_relaxed);
-}
-
 /** @brief change the execution bound
  * This means changing the maximal amount of flops per second that it may consume, regardless of what the host may
  * deliver. Currently, this cannot be changed once the exec started.
@@ -139,7 +126,7 @@ ExecPtr Exec::set_priority(double priority)
 ExecSeq::ExecSeq(sg_host_t host, double flops_amount) : Exec(), flops_amount_(flops_amount)
 {
   Activity::set_remaining(flops_amount_);
-  boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->set_host(host);
+  boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->set_host(host);
 }
 
 Exec* ExecSeq::start()
@@ -167,16 +154,16 @@ ExecPtr ExecSeq::set_host(Host* host)
   xbt_assert(state_ == State::INITED || state_ == State::STARTED,
              "Cannot change the host of an exec once it's done (state: %d)", (int)state_);
   if (state_ == State::STARTED)
-    boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->migrate(host);
-  boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->set_host(host);
+    boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->migrate(host);
+  boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->set_host(host);
   return this;
 }
 
 /** @brief Returns the amount of flops that remain to be done */
 double ExecSeq::get_remaining()
 {
-  return simgrid::kernel::actor::simcall(
-      [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->get_remaining(); });
+  return kernel::actor::simcall(
+      [this]() { return boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->get_remaining(); });
 }
 
 /** @brief Returns the ratio of elements that are still to do
@@ -185,9 +172,8 @@ double ExecSeq::get_remaining()
  */
 double ExecSeq::get_remaining_ratio()
 {
-  return simgrid::kernel::actor::simcall([this]() {
-    return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->get_seq_remaining_ratio();
-  });
+  return kernel::actor::simcall(
+      [this]() { return boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->get_seq_remaining_ratio(); });
 }
 
 ///////////// PARALLEL EXECUTIONS ////////