X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/23e5ed757886487772d8d084c59103a1ec881b61..4a13db94f50023e3e9ad850b936b69b5f85b7fb7:/src/s4u/s4u_exec.cpp diff --git a/src/s4u/s4u_exec.cpp b/src/s4u/s4u_exec.cpp index bc78b1ec70..3b90193f74 100644 --- a/src/s4u/s4u_exec.cpp +++ b/src/s4u/s4u_exec.cpp @@ -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(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; } +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(pimpl_)->migrate(host); + host_ = host; + return this; +} + double Exec::getRemains() { return simgrid::simix::kernelImmediate( [this]() { return boost::static_pointer_cast(pimpl_)->remains(); }); } +double Exec::getRemainingRatio() +{ + return simgrid::simix::kernelImmediate( + [this]() { return boost::static_pointer_cast(pimpl_)->remainingRatio(); }); +} void intrusive_ptr_release(simgrid::s4u::Exec* e) {