Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factor Activity::wait() and wait_for() through CRTP.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 21 Apr 2021 22:02:17 +0000 (00:02 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 22 Apr 2021 08:07:32 +0000 (10:07 +0200)
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Io.hpp
src/s4u/s4u_Activity.cpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp

index a1c1968..3e31a94 100644 (file)
@@ -108,10 +108,10 @@ public:
    */
   virtual Activity* start() = 0;
   /** Blocks the current actor until the activity is terminated */
-  virtual Activity* wait() = 0;
+  Activity* wait() { return wait_for(-1.0); }
   /** Blocks the current actor until the activity is terminated, or until the timeout is elapsed\n
    *  Raises: timeout exception.*/
-  virtual Activity* wait_for(double timeout) = 0;
+  Activity* wait_for(double timeout);
   /** Blocks the current actor until the activity is terminated, or until the time limit is reached\n
    * Raises: timeout exception. */
   void wait_until(double time_limit);
@@ -221,6 +221,9 @@ public:
   }
 
   AnyActivity* cancel() { return static_cast<AnyActivity*>(Activity::cancel()); }
+  AnyActivity* wait() { return wait_for(-1.0); }
+  virtual AnyActivity* wait_for(double timeout) { return static_cast<AnyActivity*>(Activity::wait_for(timeout)); }
+
 #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
index 5291c7c..9fb2288 100644 (file)
@@ -79,7 +79,6 @@ public:
   static int test_any(const std::vector<CommPtr>* comms);
 
   Comm* start() override;
-  Comm* wait() override;
   Comm* wait_for(double timeout) override;
   bool test() override;
 
index d4149aa..ac5b5f6 100644 (file)
@@ -50,8 +50,7 @@ public:
 
   static ExecPtr init();
   Exec* start() override;
-  Exec* wait() override;
-  Exec* wait_for(double timeout) override;
+
   /*! take a vector of s4u::ExecPtr and return when one of them is finished.
    * The return value is the rank of the first finished ExecPtr. */
   static int wait_any(std::vector<ExecPtr>* execs) { return wait_any_for(execs, -1); }
index 5fe8f69..5752373 100644 (file)
@@ -35,8 +35,6 @@ public:
 
   static IoPtr init();
   Io* start() override;
-  Io* wait() override;
-  Io* wait_for(double timeout) override;
 
   double get_remaining() const override;
   sg_size_t get_performed_ioops() const;
index 00b3ff4..7b32938 100644 (file)
@@ -8,6 +8,7 @@
 #include "simgrid/s4u/Activity.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "src/kernel/activity/ActivityImpl.hpp"
+#include "src/kernel/actor/ActorImpl.hpp"
 
 XBT_LOG_EXTERNAL_CATEGORY(s4u);
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activity, s4u, "S4U activities");
@@ -22,6 +23,17 @@ void Activity::wait_until(double time_limit)
     wait_for(time_limit - now);
 }
 
+Activity* Activity::wait_for(double timeout)
+{
+  if (state_ == State::INITED)
+    vetoable_start();
+
+  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
+  kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
+  complete(State::FINISHED);
+  return this;
+}
+
 bool Activity::test()
 {
   xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
index 8d747ed..b0c22d8 100644 (file)
@@ -182,12 +182,6 @@ Comm* Comm::start()
   return this;
 }
 
-/** @brief Block the calling actor until the communication is finished */
-Comm* Comm::wait()
-{
-  return this->wait_for(-1);
-}
-
 /** @brief Block the calling actor until the communication is finished, or until timeout
  *
  * On timeout, an exception is thrown and the communication is invalidated.
index 0fa076c..2ae3ad2 100644 (file)
@@ -54,22 +54,6 @@ Exec* Exec::start()
   return this;
 }
 
-Exec* Exec::wait()
-{
-  return this->wait_for(-1);
-}
-
-Exec* Exec::wait_for(double timeout)
-{
-  if (state_ == State::INITED)
-    vetoable_start();
-
-  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
-  kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
-  complete(State::FINISHED);
-  return this;
-}
-
 int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
 {
   std::vector<kernel::activity::ExecImpl*> rexecs(execs->size());
index 548513b..733b481 100644 (file)
@@ -45,22 +45,6 @@ Io* Io::start()
   return this;
 }
 
-Io* Io::wait()
-{
-  return this->wait_for(-1);
-}
-
-Io* Io::wait_for(double timeout)
-{
-  if (state_ == State::INITED)
-    vetoable_start();
-
-  kernel::actor::ActorImpl* issuer = kernel::actor::ActorImpl::self();
-  kernel::actor::simcall_blocking([this, issuer, timeout] { this->get_impl()->wait_for(issuer, timeout); });
-  complete(state_ = State::FINISHED);
-  return this;
-}
-
 IoPtr Io::set_disk(const_sg_disk_t disk)
 {
   xbt_assert(state_ == State::INITED || state_ == State::STARTING, "Cannot set disk once the Io is started");