Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factor Activity::cancel() through CRTP.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 21 Apr 2021 21:38:18 +0000 (23:38 +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 74ca77e..a1c1968 100644 (file)
@@ -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<AnyActivity*>(this);
   }
+
+  AnyActivity* cancel() { return static_cast<AnyActivity*>(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
index 47668bf..5291c7c 100644 (file)
@@ -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. */
index 9a51dd0..d4149aa 100644 (file)
@@ -57,7 +57,6 @@ public:
   static int wait_any(std::vector<ExecPtr>* 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<ExecPtr>* 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. */
index 685f555..5fe8f69 100644 (file)
@@ -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;
index 002035c..00b3ff4 100644 (file)
@@ -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_)
index 5ffb612..8d747ed 100644 (file)
@@ -251,16 +251,6 @@ Comm* Comm::detach()
   return this;
 }
 
-Comm* Comm::cancel()
-{
-  kernel::actor::simcall([this] {
-    if (pimpl_)
-      boost::static_pointer_cast<kernel::activity::CommImpl>(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 ||
index 324e2ab..0fa076c 100644 (file)
@@ -88,13 +88,6 @@ int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
   return changed_pos;
 }
 
-Exec* Exec::cancel()
-{
-  kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::ExecImpl>(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.
index 570070d..548513b 100644 (file)
@@ -45,13 +45,6 @@ Io* Io::start()
   return this;
 }
 
-Io* Io::cancel()
-{
-  kernel::actor::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
-  complete(State::CANCELED);
-  return this;
-}
-
 Io* Io::wait()
 {
   return this->wait_for(-1);