Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove superfluous indirection.
[simgrid.git] / src / s4u / s4u_exec.cpp
index bc78b1e..0e2d39b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2018. 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. */
@@ -13,32 +13,40 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous execut
 namespace simgrid {
 namespace s4u {
 
-void Exec::start()
+Activity* Exec::start()
 {
-  pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
-  state_ = started;
+  pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0., host_);
+  boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->setBound(bound_);
+  state_ = State::started;
+  return this;
 }
 
-void Exec::wait()
+Activity* Exec::wait()
 {
-  this->wait(-1);
+  simcall_execution_wait(pimpl_);
+  state_ = State::finished;
+  return this;
 }
 
-void Exec::wait(double timeout)
+Activity* Exec::wait(double timeout)
 {
-  simcall_execution_wait(pimpl_);
+  THROW_UNIMPLEMENTED;
+  return this;
 }
 
 bool Exec::test()
 {
-  xbt_assert(state_ == inited || state_ == started || state_ == finished);
+  xbt_assert(state_ == State::inited || state_ == State::started || state_ == State::finished);
 
-  if (state_ == finished) {
+  if (state_ == State::finished)
     return true;
-  }
 
-  if (state_ == inited) {
+  if (state_ == State::inited)
     this->start();
+
+  if (simcall_execution_test(pimpl_)) {
+    state_ = State::finished;
+    return true;
   }
 
   return false;
@@ -46,15 +54,38 @@ bool Exec::test()
 
 ExecPtr Exec::setPriority(double priority)
 {
+  xbt_assert(state_ == State::inited, "Cannot change the priority of an exec after its start");
   priority_ = priority;
   return this;
 }
 
-double Exec::getRemains()
+ExecPtr Exec::setBound(double bound)
+{
+  xbt_assert(state_ == State::inited, "Cannot change the bound of an exec after its start");
+  bound_ = bound;
+  return this;
+}
+
+ExecPtr Exec::setHost(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);
+  host_ = host;
+  return this;
+}
+
+double Exec::get_remaining()
 {
   return simgrid::simix::kernelImmediate(
       [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
 }
+double Exec::getRemainingRatio()
+{
+  return simgrid::simix::kernelImmediate(
+      [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remainingRatio(); });
+}
 
 void intrusive_ptr_release(simgrid::s4u::Exec* e)
 {