Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rework SleepImpl (and save a cast)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 14 Mar 2019 15:29:28 +0000 (16:29 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 14 Mar 2019 15:29:28 +0000 (16:29 +0100)
src/kernel/activity/SleepImpl.cpp
src/kernel/activity/SleepImpl.hpp
src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp

index addab36..fd85d9d 100644 (file)
@@ -18,9 +18,27 @@ namespace simgrid {
 namespace kernel {
 namespace activity {
 
 namespace kernel {
 namespace activity {
 
-SleepImpl* SleepImpl::start(double duration)
+SleepImplPtr SleepImpl::set_name(const std::string& name)
 {
 {
-  surf_action_ = host_->pimpl_cpu->sleep(duration);
+  ActivityImpl::set_name(name);
+  return this;
+}
+
+SleepImplPtr SleepImpl::set_host(s4u::Host* host)
+{
+  host_ = host;
+  return this;
+}
+
+SleepImplPtr SleepImpl::set_duration(double duration)
+{
+  duration_ = duration;
+  return this;
+}
+
+SleepImpl* SleepImpl::start()
+{
+  surf_action_ = host_->pimpl_cpu->sleep(duration_);
   surf_action_->set_data(this);
   XBT_DEBUG("Create sleep synchronization %p", this);
   return this;
   surf_action_->set_data(this);
   XBT_DEBUG("Create sleep synchronization %p", this);
   return this;
@@ -66,7 +84,6 @@ void SleepImpl::post()
       SIMIX_simcall_answer(simcall);
     }
   }
       SIMIX_simcall_answer(simcall);
     }
   }
-
   SIMIX_process_sleep_destroy(this);
 }
 void SleepImpl::finish()
   SIMIX_process_sleep_destroy(this);
 }
 void SleepImpl::finish()
index d4f83e0..30a004c 100644 (file)
@@ -14,13 +14,16 @@ namespace kernel {
 namespace activity {
 
 class XBT_PUBLIC SleepImpl : public ActivityImpl {
 namespace activity {
 
 class XBT_PUBLIC SleepImpl : public ActivityImpl {
+  sg_host_t host_  = nullptr;
+  double duration_ = 0;
+
 public:
 public:
-  explicit SleepImpl(const std::string& name, s4u::Host* host) : ActivityImpl(name), host_(host) {}
+  SleepImplPtr set_name(const std::string& name);
+  SleepImplPtr set_host(s4u::Host* host);
+  SleepImplPtr set_duration(double duration);
   void post() override;
   void finish() override;
   void post() override;
   void finish() override;
-  SleepImpl* start(double duration);
-
-  sg_host_t host_ = nullptr;
+  SleepImpl* start();
 };
 } // namespace activity
 } // namespace kernel
 };
 } // namespace activity
 } // namespace kernel
index 1c2fcfb..728f23d 100644 (file)
@@ -388,7 +388,11 @@ activity::ActivityImplPtr ActorImpl::sleep(double duration)
     throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
         XBT_THROW_POINT, std::string("Host ") + host_->get_cname() + " failed, you cannot sleep there.")));
 
     throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
         XBT_THROW_POINT, std::string("Host ") + host_->get_cname() + " failed, you cannot sleep there.")));
 
-  return activity::SleepImplPtr(new activity::SleepImpl("sleep", host_))->start(duration);
+  return activity::SleepImplPtr(new activity::SleepImpl())
+      ->set_name("sleep")
+      ->set_host(host_)
+      ->set_duration(duration)
+      ->start();
 }
 
 void ActorImpl::throw_exception(std::exception_ptr e)
 }
 
 void ActorImpl::throw_exception(std::exception_ptr e)
@@ -413,7 +417,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(waiting_synchro);
+      SIMIX_process_sleep_destroy(sleep);
       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()) {
@@ -564,7 +568,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(actor->waiting_synchro);
+      SIMIX_process_sleep_destroy(sleep);
       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()) {
@@ -665,11 +669,9 @@ 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(smx_activity_t synchro)
+void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr sleep)
 {
 {
-  XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
-  simgrid::kernel::activity::SleepImplPtr sleep =
-      boost::static_pointer_cast<simgrid::kernel::activity::SleepImpl>(synchro);
+  XBT_DEBUG("Destroy sleep synchro %p", sleep.get());
 
   if (sleep->surf_action_) {
     sleep->surf_action_->unref();
 
   if (sleep->surf_action_) {
     sleep->surf_action_->unref();
index 3dc9224..cef9f09 100644 (file)
@@ -181,6 +181,6 @@ 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(smx_activity_t synchro);
+XBT_PRIVATE void SIMIX_process_sleep_destroy(simgrid::kernel::activity::SleepImplPtr synchro);
 
 #endif
 
 #endif