X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/237fd22b56db7d1c67360c37559ce3aab16a002d..15178c7908a80843a430025313d143b7cb52d06a:/src/s4u/s4u_Exec.cpp diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index ab680d81ae..633284da0d 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -1,47 +1,45 @@ -/* 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. */ -#include "simgrid/Exception.hpp" -#include "simgrid/exec.h" -#include "simgrid/s4u/Actor.hpp" -#include "simgrid/s4u/Exec.hpp" -#include "simgrid/s4u/Host.hpp" +#include +#include +#include +#include + #include "src/kernel/activity/ExecImpl.hpp" #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/actor/SimcallObserver.hpp" -#include "xbt/log.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous executions"); namespace simgrid { namespace s4u { xbt::signal Exec::on_start; -xbt::signal Exec::on_completion; Exec::Exec(kernel::activity::ExecImplPtr pimpl) { pimpl_ = pimpl; } -void Exec::complete(Activity::State state) +void Exec::reset() const { - Activity::complete(state); - on_completion(*this); + boost::static_pointer_cast(pimpl_)->reset(); } ExecPtr Exec::init() { auto pimpl = kernel::activity::ExecImplPtr(new kernel::activity::ExecImpl()); - Host::on_state_change.connect([pimpl](s4u::Host const& h) { - if (not h.is_on() && pimpl->state_ == kernel::activity::State::RUNNING && + unsigned int cb_id = Host::on_state_change.connect([pimpl](s4u::Host const& h) { + 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(); } }); - return ExecPtr(pimpl->get_iface()); + pimpl->set_cb_id(cb_id); + return ExecPtr(static_cast(pimpl->get_iface())); } Exec* Exec::start() @@ -108,6 +106,14 @@ ExecPtr Exec::set_priority(double priority) return this; } +ExecPtr Exec::update_priority(double priority) +{ + kernel::actor::simcall([this, priority] { + boost::static_pointer_cast(pimpl_)->update_sharing_penalty(1. / priority); + }); + return this; +} + ExecPtr Exec::set_flops_amount(double flops_amount) { xbt_assert(state_ == State::INITED || state_ == State::STARTING, @@ -153,16 +159,6 @@ unsigned int Exec::get_host_number() const return static_cast(pimpl_.get())->get_host_number(); } -double Exec::get_start_time() const -{ - return static_cast(pimpl_.get())->get_start_time(); -} - -double Exec::get_finish_time() const -{ - return static_cast(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). */ @@ -200,6 +196,22 @@ ExecPtr Exec::set_hosts(const std::vector& hosts) return this; } +ExecPtr Exec::unset_host() +{ + if (not is_assigned()) + throw std::invalid_argument( + xbt::string_printf("Exec %s: the activity is not assigned to any host(s)", get_cname())); + else { + reset(); + + if (state_ == State::STARTED) + cancel(); + vetoable_start(); + + return this; + } +} + double Exec::get_cost() const { return (pimpl_->surf_action_ == nullptr) ? -1 : pimpl_->surf_action_->get_cost();