Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not clean twice in Activity::post(), so that even test() can call it
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 23 Feb 2023 22:16:03 +0000 (23:16 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 23 Feb 2023 22:16:03 +0000 (23:16 +0100)
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/IoImpl.cpp

index f425dc8..39f6d47 100644 (file)
@@ -63,7 +63,7 @@ const char* ActivityImpl::get_state_str() const
 bool ActivityImpl::test(actor::ActorImpl* issuer)
 {
   if (state_ != State::WAITING && state_ != State::RUNNING) {
-    finish();
+    post();
     issuer->exception_ = nullptr; // Do not propagate exception in that case
     return true;
   }
@@ -106,7 +106,7 @@ void ActivityImpl::wait_for(actor::ActorImpl* issuer, double timeout)
 
   /* If the synchro is already finished then perform the error handling */
   if (state_ != State::WAITING && state_ != State::RUNNING) {
-    finish();
+    post();
   } else {
     /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
     /* Comms handle that a bit differently of the other activities */
@@ -145,7 +145,7 @@ void ActivityImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<Acti
       act->simcalls_.push_back(&issuer->simcall_);
       observer->set_result(idx);
       act->set_state(State::DONE);
-      act->finish();
+      act->post();
     }
     return;
   }
@@ -167,7 +167,7 @@ void ActivityImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<Acti
     act->simcalls_.push_back(&issuer->simcall_);
     /* see if the synchro is already finished */
     if (act->get_state() != State::WAITING && act->get_state() != State::RUNNING) {
-      act->finish();
+      act->post();
       break;
     }
   }
index d7368f6..a6789b1 100644 (file)
@@ -135,23 +135,25 @@ ExecImpl& ExecImpl::update_sharing_penalty(double sharing_penalty)
 
 void ExecImpl::post()
 {
-  xbt_assert(model_action_ != nullptr);
-  if (auto const& hosts = get_hosts();
-      std::any_of(hosts.begin(), hosts.end(), [](const s4u::Host* host) { return not host->is_on(); })) {
-    /* If one of the hosts running the synchro failed, notice it. This way, the asking
-     * process can be killed if it runs on that host itself */
-    set_state(State::FAILED);
-  } else if (model_action_->get_state() == resource::Action::State::FAILED) {
-    /* If all the hosts are running the synchro didn't fail, then the synchro was canceled */
-    set_state(State::CANCELED);
-  } else {
-    set_state(State::DONE);
+  if (model_action_ != nullptr) {
+    if (auto const& hosts = get_hosts();
+        std::any_of(hosts.begin(), hosts.end(), [](const s4u::Host* host) { return not host->is_on(); })) {
+      /* If one of the hosts running the synchro failed, notice it. This way, the asking
+       * process can be killed if it runs on that host itself */
+      set_state(State::FAILED);
+    } else if (model_action_->get_state() == resource::Action::State::FAILED) {
+      /* If all the hosts are running the synchro didn't fail, then the synchro was canceled */
+      set_state(State::CANCELED);
+    } else {
+      set_state(State::DONE);
+    }
+
+    clean_action();
   }
 
-  clean_action();
-  if (get_actor() != nullptr) {
+  if (get_actor() != nullptr)
     get_actor()->activities_.erase(this);
-  }
+
   if (get_state() != State::FAILED && cb_id_ >= 0)
     s4u::Host::on_state_change.disconnect(cb_id_);
   /* Answer all simcalls associated with the synchro */
index cd57ece..c7ef218 100644 (file)
@@ -97,22 +97,24 @@ IoImpl* IoImpl::start()
 
 void IoImpl::post()
 {
-  performed_ioops_ = model_action_->get_cost();
-  if (model_action_->get_state() == resource::Action::State::FAILED) {
-    if (host_ && dst_host_) { // this is an I/O stream
-      if (not host_->is_on())
-       set_state(State::SRC_HOST_FAILURE);
-      else if (not dst_host_->is_on())
-       set_state(State::DST_HOST_FAILURE);
-    } else if ((disk_ && not disk_->is_on()) || (dst_disk_ && not dst_disk_->is_on()))
-      set_state(State::FAILED);
-    else
-      set_state(State::CANCELED);
-  } else {
-    set_state(State::DONE);
-  }
+  if (model_action_ != nullptr) {
+    performed_ioops_ = model_action_->get_cost();
+    if (model_action_->get_state() == resource::Action::State::FAILED) {
+      if (host_ && dst_host_) { // this is an I/O stream
+        if (not host_->is_on())
+          set_state(State::SRC_HOST_FAILURE);
+        else if (not dst_host_->is_on())
+          set_state(State::DST_HOST_FAILURE);
+      } else if ((disk_ && not disk_->is_on()) || (dst_disk_ && not dst_disk_->is_on()))
+        set_state(State::FAILED);
+      else
+        set_state(State::CANCELED);
+    } else {
+      set_state(State::DONE);
+    }
 
-  clean_action();
+    clean_action();
+  }
 
   /* Answer all simcalls associated with the synchro */
   finish();