Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / kernel / activity / IoImpl.cpp
index 5daae90..4eaae3b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -26,6 +26,11 @@ namespace activity {
 IoImpl::IoImpl()
 {
   piface_ = new s4u::Io(this);
+  actor::ActorImpl* self = actor::ActorImpl::self();
+  if (self) {
+    set_actor(self);
+    self->activities_.emplace_back(this);
+  }
 }
 
 IoImpl& IoImpl::set_sharing_penalty(double sharing_penalty)
@@ -74,6 +79,7 @@ IoImpl* IoImpl::start()
       disk_->get_host()->get_netpoint()->get_englobing_zone()->get_disk_model()->io_start(disk_, size_, type_);
   surf_action_->set_sharing_penalty(sharing_penalty_);
   surf_action_->set_activity(this);
+  start_time_ = surf_action_->get_start_time();
 
   XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
 
@@ -108,6 +114,25 @@ void IoImpl::post()
   /* Answer all simcalls associated with the synchro */
   finish();
 }
+void IoImpl::set_exception(actor::ActorImpl* issuer)
+{
+  switch (state_) {
+    case State::FAILED:
+      issuer->context_->set_wannadie();
+      static_cast<s4u::Io*>(get_iface())->complete(s4u::Activity::State::FAILED);
+      issuer->exception_ = std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
+      break;
+    case State::CANCELED:
+      issuer->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
+      break;
+    case State::TIMEOUT:
+      issuer->exception_ = std::make_exception_ptr(TimeoutException(XBT_THROW_POINT, "Timeouted"));
+      break;
+    default:
+      xbt_assert(state_ == State::DONE, "Internal error in IoImpl::finish(): unexpected synchro state %s",
+                 to_c_str(state_));
+  }
+}
 
 void IoImpl::finish()
 {
@@ -141,23 +166,7 @@ void IoImpl::finish()
       }
     }
 
-    switch (state_) {
-      case State::FAILED:
-        simcall->issuer_->context_->set_wannadie();
-        piface_->complete(s4u::Activity::State::FAILED);
-        simcall->issuer_->exception_ =
-            std::make_exception_ptr(StorageFailureException(XBT_THROW_POINT, "Storage failed"));
-        break;
-      case State::CANCELED:
-        simcall->issuer_->exception_ = std::make_exception_ptr(CancelException(XBT_THROW_POINT, "I/O Canceled"));
-        break;
-      case State::TIMEOUT:
-        simcall->issuer_->exception_ = std::make_exception_ptr(TimeoutException(XBT_THROW_POINT, "Timeouted"));
-        break;
-      default:
-        xbt_assert(state_ == State::DONE, "Internal error in IoImpl::finish(): unexpected synchro state %s",
-                   to_c_str(state_));
-    }
+    set_exception(simcall->issuer_);
 
     simcall->issuer_->waiting_synchro_ = nullptr;
     simcall->issuer_->simcall_answer();