Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add test() for asynchronous executions
[simgrid.git] / src / s4u / s4u_exec.cpp
index bc78b1e..ca3623d 100644 (file)
@@ -15,18 +15,18 @@ namespace s4u {
 
 void Exec::start()
 {
-  pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
+  pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0., host_);
   state_ = started;
 }
 
 void Exec::wait()
 {
-  this->wait(-1);
+  simcall_execution_wait(pimpl_);
 }
 
 void Exec::wait(double timeout)
 {
-  simcall_execution_wait(pimpl_);
+  THROW_UNIMPLEMENTED;
 }
 
 bool Exec::test()
@@ -41,20 +41,37 @@ bool Exec::test()
     this->start();
   }
 
+  if (simcall_execution_test(pimpl_)) {
+    state_ = finished;
+    return true;
+  }
+
   return false;
 }
 
 ExecPtr Exec::setPriority(double priority)
 {
+  xbt_assert(state_ == inited, "Cannot change the priority of an exec after its start");
   priority_ = priority;
   return this;
 }
+ExecPtr Exec::setHost(Host* host)
+{
+  xbt_assert(state_ == inited, "Cannot change the host of an exec after its start");
+  host_ = host;
+  return this;
+}
 
 double Exec::getRemains()
 {
   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)
 {