From 41bbb4208fd2c4d15e7ee67c43408e1da7b3a13e Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 7 Feb 2020 15:14:09 +0100 Subject: [PATCH] Define method test() in Activity (common to Exec and Io). s4u::Comm still uses old-style simcalls (thanks MC) and cannot use it now. --- include/simgrid/s4u/Activity.hpp | 5 +++-- include/simgrid/s4u/Exec.hpp | 2 -- include/simgrid/s4u/Io.hpp | 1 - src/s4u/s4u_Activity.cpp | 21 +++++++++++++++++++++ src/s4u/s4u_Exec.cpp | 20 -------------------- src/s4u/s4u_Io.cpp | 20 -------------------- 6 files changed, 24 insertions(+), 45 deletions(-) diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index e92d768c4a..c38231f4c4 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -90,8 +90,9 @@ public: /** Retrieve the current state of the activity */ Activity::State get_state() const { return state_; } void set_state(Activity::State state) { state_ = state; } - /** Tests whether the given activity is terminated yet. This is a pure function. */ - virtual bool test() = 0; + /** Tests whether the given activity is terminated yet. */ + virtual bool test(); + virtual const char* get_cname() const = 0; virtual const std::string& get_name() const = 0; diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 67792c1efb..e3892918c5 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -63,8 +63,6 @@ public: /*! 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); - bool test() override; - ExecPtr set_bound(double bound); ExecPtr set_priority(double priority); XBT_ATTRIB_DEPRECATED_v329("Please use exec_init(...)->wait_for(timeout)") ExecPtr set_timeout(double timeout); diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index 2ad47c0493..557eddfb7f 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -44,7 +44,6 @@ public: Io* wait() override; Io* wait_for(double timeout) override; Io* cancel() override; - bool test() 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 3f7404ed2a..1560c50178 100644 --- a/src/s4u/s4u_Activity.cpp +++ b/src/s4u/s4u_Activity.cpp @@ -7,6 +7,7 @@ #include "simgrid/s4u/Activity.hpp" #include "simgrid/s4u/Engine.hpp" +#include "src/kernel/activity/ActivityImpl.hpp" XBT_LOG_EXTERNAL_CATEGORY(s4u); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities"); @@ -21,6 +22,26 @@ void Activity::wait_until(double time_limit) wait_for(time_limit - now); } +bool Activity::test() +{ + xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING || + state_ == State::FINISHED); + + if (state_ == State::FINISHED) + return true; + + if (state_ == State::INITED || state_ == State::STARTING) + this->vetoable_start(); + + if (kernel::actor::simcall([this] { return this->get_impl()->test(); })) { + state_ = State::FINISHED; + this->release_dependencies(); + return true; + } + + return false; +} + double Activity::get_remaining() const { return remains_; diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index f443e16663..eb3eb3f577 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -20,26 +20,6 @@ Exec::Exec() pimpl_ = kernel::activity::ExecImplPtr(new kernel::activity::ExecImpl()); } -bool Exec::test() -{ - xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING || - state_ == State::FINISHED); - - if (state_ == State::FINISHED) - return true; - - if (state_ == State::INITED || state_ == State::STARTING) - this->vetoable_start(); - - if (kernel::actor::simcall([this] { return this->get_impl()->test(); })) { - state_ = State::FINISHED; - this->release_dependencies(); - return true; - } - - return false; -} - Exec* Exec::wait() { return this->wait_for(-1); diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index ddfaa6127b..7de8c809d5 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -69,26 +69,6 @@ Io* Io::wait_for(double timeout) return this; } -bool Io::test() -{ - xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING || - state_ == State::FINISHED); - - if (state_ == State::FINISHED) - return true; - - if (state_ == State::INITED || state_ == State::STARTING) - this->vetoable_start(); - - if (kernel::actor::simcall([this] { return this->get_impl()->test(); })) { - state_ = State::FINISHED; - this->release_dependencies(); - return true; - } - - return false; -} - /** @brief Returns the amount of flops that remain to be done */ double Io::get_remaining() const { -- 2.20.1