Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factoring with an ActivityImpl::clean_action() method
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 3 Apr 2019 08:07:32 +0000 (10:07 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 3 Apr 2019 08:07:32 +0000 (10:07 +0200)
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/ActivityImpl.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/CommImpl.hpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/SleepImpl.cpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp

index be0e1b0..da8f12d 100644 (file)
@@ -12,10 +12,15 @@ namespace kernel {
 namespace activity {
 
 ActivityImpl::~ActivityImpl()
 namespace activity {
 
 ActivityImpl::~ActivityImpl()
+{
+  clean_action();
+  XBT_DEBUG("Destroy activity %p", this);
+}
+
+void ActivityImpl::clean_action()
 {
   if (surf_action_) {
     surf_action_->unref();
 {
   if (surf_action_) {
     surf_action_->unref();
-    XBT_DEBUG("Destroy activity %p", this);
     surf_action_ = nullptr;
   }
 }
     surf_action_ = nullptr;
   }
 }
index 1719af4..0d16180 100644 (file)
@@ -35,6 +35,7 @@ public:
   virtual void post()   = 0; // What to do when a simcall terminates
   virtual void finish() = 0;
 
   virtual void post()   = 0; // What to do when a simcall terminates
   virtual void finish() = 0;
 
+  virtual void clean_action();
   virtual double get_remaining() const;
   // boost::intrusive_ptr<ActivityImpl> support:
   friend XBT_PUBLIC void intrusive_ptr_add_ref(ActivityImpl* activity);
   virtual double get_remaining() const;
   // boost::intrusive_ptr<ActivityImpl> support:
   friend XBT_PUBLIC void intrusive_ptr_add_ref(ActivityImpl* activity);
index 5852dad..8aa5747 100644 (file)
@@ -520,10 +520,7 @@ void CommImpl::cancel()
 /** @brief This is part of the cleanup process, probably an internal command */
 void CommImpl::cleanupSurf()
 {
 /** @brief This is part of the cleanup process, probably an internal command */
 void CommImpl::cleanupSurf()
 {
-  if (surf_action_) {
-    surf_action_->unref();
-    surf_action_ = nullptr;
-  }
+  clean_action();
 
   if (src_timeout_) {
     src_timeout_->unref();
 
   if (src_timeout_) {
     src_timeout_->unref();
index ca65fd0..777d826 100644 (file)
@@ -27,18 +27,19 @@ public:
 
   CommImpl& set_type(CommImpl::Type type);
   CommImpl& set_size(double size);
 
   CommImpl& set_type(CommImpl::Type type);
   CommImpl& set_size(double size);
-  double get_rate() { return rate_; }
-  CommImpl& set_rate(double rate);
   CommImpl& set_src_buff(void* buff, size_t size);
   CommImpl& set_dst_buff(void* buff, size_t* size);
   CommImpl& set_src_buff(void* buff, size_t size);
   CommImpl& set_dst_buff(void* buff, size_t* size);
+  CommImpl& set_rate(double rate);
+  double get_rate() { return rate_; }
 
 
-  CommImpl* start();
   void copy_data();
   void copy_data();
+
+  CommImpl* start();
   void suspend() override;
   void resume() override;
   void suspend() override;
   void resume() override;
+  void cancel() override;
   void post() override;
   void finish() override;
   void post() override;
   void finish() override;
-  void cancel() override;
 
   CommImpl::Type type_;        /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
   MailboxImpl* mbox = nullptr; /* Rendez-vous where the comm is queued */
 
   CommImpl::Type type_;        /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
   MailboxImpl* mbox = nullptr; /* Rendez-vous where the comm is queued */
index 0e4d8ed..5c12267 100644 (file)
@@ -164,10 +164,8 @@ void ExecImpl::post()
 
   on_completion(*this);
 
 
   on_completion(*this);
 
-  if (surf_action_) {
-    surf_action_->unref();
-    surf_action_ = nullptr;
-  }
+  clean_action();
+
   if (timeout_detector_) {
     timeout_detector_->unref();
     timeout_detector_ = nullptr;
   if (timeout_detector_) {
     timeout_detector_->unref();
     timeout_detector_ = nullptr;
index d236948..b5b7a7a 100644 (file)
@@ -73,7 +73,8 @@ void SleepImpl::finish()
       SIMIX_simcall_answer(simcall);
     }
   }
       SIMIX_simcall_answer(simcall);
     }
   }
-  SIMIX_process_sleep_destroy(this);
+
+  clean_action();
 }
 } // namespace activity
 } // namespace kernel
 }
 } // namespace activity
 } // namespace kernel
index 8f78d87..af4a2b5 100644 (file)
@@ -207,8 +207,7 @@ void ActorImpl::exit()
 
     if (exec != nullptr && exec->surf_action_) {
       exec->cancel();
 
     if (exec != nullptr && exec->surf_action_) {
       exec->cancel();
-      exec->surf_action_->unref();
-      exec->surf_action_ = nullptr;
+      exec->clean_action();
     } else if (comm != nullptr) {
       comms.remove(waiting_synchro);
       comm->cancel();
     } else if (comm != nullptr) {
       comms.remove(waiting_synchro);
       comm->cancel();
@@ -438,7 +437,7 @@ void ActorImpl::throw_exception(std::exception_ptr e)
 
     activity::SleepImplPtr sleep = boost::dynamic_pointer_cast<activity::SleepImpl>(waiting_synchro);
     if (sleep != nullptr) {
 
     activity::SleepImplPtr sleep = boost::dynamic_pointer_cast<activity::SleepImpl>(waiting_synchro);
     if (sleep != nullptr) {
-      SIMIX_process_sleep_destroy(sleep);
+      sleep->clean_action();
       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) ==
               end(simix_global->actors_to_run) &&
           this != SIMIX_process_self()) {
       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) ==
               end(simix_global->actors_to_run) &&
           this != SIMIX_process_self()) {
@@ -589,7 +588,7 @@ void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const c
     simgrid::kernel::activity::SleepImplPtr sleep =
         boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
     if (sleep != nullptr) {
     simgrid::kernel::activity::SleepImplPtr sleep =
         boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
     if (sleep != nullptr) {
-      SIMIX_process_sleep_destroy(sleep);
+      sleep->clean_action();
       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) ==
               end(simix_global->actors_to_run) &&
           actor != SIMIX_process_self()) {
       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) ==
               end(simix_global->actors_to_run) &&
           actor != SIMIX_process_self()) {
@@ -690,16 +689,6 @@ void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration)
   simcall->issuer->waiting_synchro = sync;
 }
 
   simcall->issuer->waiting_synchro = sync;
 }
 
-void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr sleep)
-{
-  XBT_DEBUG("Destroy sleep synchro %p", sleep.get());
-
-  if (sleep->surf_action_) {
-    sleep->surf_action_->unref();
-    sleep->surf_action_ = nullptr;
-  }
-}
-
 /**
  * @brief Calling this function makes the process to yield.
  *
 /**
  * @brief Calling this function makes the process to yield.
  *
index f4ee3a8..c6324ec 100644 (file)
@@ -176,6 +176,4 @@ XBT_PUBLIC void create_maestro(const std::function<void()>& code);
 
 extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor);
 
 
 extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor);
 
-XBT_PRIVATE void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr synchro);
-
 #endif
 #endif