From 7e9f2171250125a29ef5cedc0fd69328cb819f91 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 24 Aug 2018 15:14:25 +0200 Subject: [PATCH] New function: s4u::Activity::test() Previously, it was only in some of the subclasses (also, hide some deprecated symbols from Doxygen) --- include/simgrid/s4u/Activity.hpp | 6 ++++++ include/simgrid/s4u/Comm.hpp | 4 +++- include/simgrid/s4u/Exec.hpp | 2 +- include/simgrid/s4u/Io.hpp | 1 + src/s4u/s4u_Comm.cpp | 3 +-- src/s4u/s4u_Io.cpp | 15 +++++++++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index 8c08594ae6..3a374a40ca 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -43,8 +43,10 @@ protected: virtual ~Activity() = default; public: +#ifndef DOXYGEN Activity(Activity const&) = delete; Activity& operator=(Activity const&) = delete; +#endif enum class State { INITED = 0, STARTED, CANCELED, ERRORED, FINISHED }; @@ -64,6 +66,8 @@ public: virtual Activity* cancel() = 0; /** Retrieve the current state of the activity */ Activity::State get_state() { return state_; } + /** Returns whether this activity is completed */ + virtual bool test() = 0; /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */ virtual double get_remaining(); @@ -82,6 +86,7 @@ public: /** Retrieve the user data of the Activity */ void* get_user_data() { return user_data_; } +#ifndef DOXYGEN /** @deprecated See Activity::get_state()*/ XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_state()") Activity::State getState() { return state_; } /** @deprecated See Activity::get_remaining() */ @@ -98,6 +103,7 @@ public: } /** @deprecated See Activity::get_user_data() */ XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_user_data()") void* getUserData() { return user_data_; } +#endif private: simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr; diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 4eef82f2fe..a057630588 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -45,6 +45,7 @@ public: Activity* start() override; Activity* wait() override; Activity* wait(double timeout) override; + bool test() override; /** Start the comm, and ignore its result. It can be completely forgotten after that. */ Activity* detach(); @@ -72,12 +73,12 @@ public: /** Retrieve the size of the received data */ size_t get_dst_data_size(); - bool test(); Activity* cancel() override; /** Retrieve the mailbox on which this comm acts */ MailboxPtr get_mailbox(); +#ifndef DOXYGEN /** @deprecated See Comm::set_rate() */ XBT_ATTRIB_DEPRECATED_v323("Please use Comm::set_rate()") Activity* setRate(double rate) { return set_rate(rate); } /** @deprecated See Comm::set_src_data() */ @@ -112,6 +113,7 @@ public: } /** @deprecated See Comm::get_mailbox() */ XBT_ATTRIB_DEPRECATED_v323("Please use Comm::get_mailbox()") MailboxPtr getMailbox() { return get_mailbox(); } +#endif private: double rate_ = -1; diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index c50118dcbb..94e64f3bda 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -35,7 +35,7 @@ public: Activity* wait() override; Activity* wait(double timeout) override; Activity* cancel() override; - bool test(); + bool test() override; ExecPtr set_priority(double priority); ExecPtr set_bound(double bound); diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index b47c7e7fe0..2bbdb75042 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -37,6 +37,7 @@ public: Activity* wait() override; Activity* wait(double timeout) override; Activity* cancel() override; + bool test() override; double get_remaining() override; sg_size_t get_performed_ioops(); diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index bebc91b952..a5d5e5f501 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -53,9 +53,8 @@ void Comm::wait_all(std::vector* comms) { // TODO: this should be a simcall or something // TODO: we are missing a version with timeout - for (CommPtr comm : *comms) { + for (CommPtr comm : *comms) comm->wait(); - } } Activity* Comm::set_rate(double rate) diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index e77c117486..c80bd87635 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -44,6 +44,21 @@ Activity* Io::wait(double timeout) return this; } +bool Io::test() +{ + xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED); + + if (state_ == State::FINISHED) + return true; + + if (state_ == State::INITED) + this->start(); + + THROW_UNIMPLEMENTED; + + return false; +} + /** @brief Returns the amount of flops that remain to be done */ double Io::get_remaining() { -- 2.20.1