From: Arnaud Giersch Date: Wed, 21 Apr 2021 21:38:18 +0000 (+0200) Subject: Factor Activity::cancel() through CRTP. X-Git-Tag: v3.28~428 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d9b336fd19ff354bdf49ff12183e92e678da007a Factor Activity::cancel() through CRTP. --- diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index 74ca77e2f6..a1c196844f 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -117,7 +117,7 @@ public: void wait_until(double time_limit); /** Cancel that activity */ - virtual Activity* cancel() = 0; + Activity* cancel(); /** Retrieve the current state of the activity */ Activity::State get_state() const { return state_; } /** Return a string representation of the activity's state (one of INITED, STARTING, STARTED, CANCELED, FINISHED) */ @@ -219,6 +219,8 @@ public: Activity::vetoable_start(); return static_cast(this); } + + AnyActivity* cancel() { return static_cast(Activity::cancel()); } #ifndef DOXYGEN /* The refcounting is done in the ancestor class, Activity, but we want each of the classes benefiting of the CRTP * (Exec, Comm, etc) to have smart pointers too, so we define these methods here, that forward the ptr_release and diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 47668bf84b..5291c7c75c 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -81,7 +81,6 @@ public: Comm* start() override; Comm* wait() override; Comm* wait_for(double timeout) override; - Comm* cancel() override; bool test() override; /** Start the comm, and ignore its result. It can be completely forgotten after that. */ diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 9a51dd022c..d4149aabf8 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -57,7 +57,6 @@ public: static int wait_any(std::vector* execs) { return wait_any_for(execs, -1); } /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/ static int wait_any_for(std::vector* execs, double timeout); - Exec* cancel() override; /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on * parallel executions. */ diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index 685f555eed..5fe8f69ff9 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -37,7 +37,6 @@ public: Io* start() override; Io* wait() override; Io* wait_for(double timeout) override; - Io* cancel() override; double get_remaining() const override; sg_size_t get_performed_ioops() const; diff --git a/src/s4u/s4u_Activity.cpp b/src/s4u/s4u_Activity.cpp index 002035cfa0..00b3ff49a1 100644 --- a/src/s4u/s4u_Activity.cpp +++ b/src/s4u/s4u_Activity.cpp @@ -41,6 +41,13 @@ bool Activity::test() return false; } +Activity* Activity::cancel() +{ + kernel::actor::simcall([this] { pimpl_->cancel(); }); + complete(State::CANCELED); + return this; +} + Activity* Activity::suspend() { if (suspended_) diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index 5ffb612d05..8d747ed1a6 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -251,16 +251,6 @@ Comm* Comm::detach() return this; } -Comm* Comm::cancel() -{ - kernel::actor::simcall([this] { - if (pimpl_) - boost::static_pointer_cast(pimpl_)->cancel(); - }); - complete(State::CANCELED); - return this; -} - bool Comm::test() // TODO: merge with Activity::test, once modernized { xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING || diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 324e2abf62..0fa076c358 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -88,13 +88,6 @@ int Exec::wait_any_for(std::vector* execs, double timeout) return changed_pos; } -Exec* Exec::cancel() -{ - kernel::actor::simcall([this] { boost::static_pointer_cast(pimpl_)->cancel(); }); - complete(State::CANCELED); - return this; -} - /** @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. diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index 570070d008..548513b19e 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -45,13 +45,6 @@ Io* Io::start() return this; } -Io* Io::cancel() -{ - kernel::actor::simcall([this] { boost::static_pointer_cast(pimpl_)->cancel(); }); - complete(State::CANCELED); - return this; -} - Io* Io::wait() { return this->wait_for(-1);