Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a StorageFailureException
[simgrid.git] / src / kernel / activity / IoImpl.cpp
index fd99cca..5fac5af 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2019. 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. */
@@ -6,56 +6,54 @@
 #include "src/kernel/activity/IoImpl.hpp"
 #include "simgrid/kernel/resource/Action.hpp"
 #include "src/simix/smx_io_private.hpp"
+#include "src/surf/StorageImpl.hpp"
 
-simgrid::kernel::activity::IoImpl::IoImpl(std::string name, resource::Action* surf_action, s4u::Storage* storage)
-    : ActivityImpl(name), storage_(storage), surf_action_(surf_action)
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_io);
+namespace simgrid {
+namespace kernel {
+namespace activity {
+
+IoImpl::IoImpl(std::string name, surf::StorageImpl* storage) : ActivityImpl(std::move(name)), storage_(storage)
 {
   this->state_ = SIMIX_RUNNING;
 
-  surf_action_->set_data(this);
-
-  XBT_DEBUG("Create exec %p", this);
+  XBT_DEBUG("Create io impl %p", this);
 }
 
-void simgrid::kernel::activity::IoImpl::cancel()
+IoImpl::~IoImpl()
 {
-  XBT_VERB("This exec %p is canceled", this);
   if (surf_action_ != nullptr)
-    surf_action_->cancel();
+    surf_action_->unref();
+  XBT_DEBUG("Destroy io %p", this);
 }
 
-void simgrid::kernel::activity::IoImpl::suspend()
+IoImpl* IoImpl::start(sg_size_t size, simgrid::s4u::Io::OpType type)
 {
-  if (surf_action_ != nullptr)
-    surf_action_->suspend();
+  surf_action_ = storage_->io_start(size, type);
+  surf_action_->set_data(this);
+
+  XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
+  simgrid::kernel::activity::IoImpl::on_start(this);
+
+  return this;
 }
 
-void simgrid::kernel::activity::IoImpl::resume()
+void IoImpl::cancel()
 {
+  XBT_VERB("This exec %p is canceled", this);
   if (surf_action_ != nullptr)
-    surf_action_->resume();
+    surf_action_->cancel();
+  state_ = SIMIX_CANCELED;
 }
 
-double simgrid::kernel::activity::IoImpl::get_remaining()
+double IoImpl::get_remaining()
 {
   return surf_action_ ? surf_action_->get_remains() : 0;
 }
 
-void simgrid::kernel::activity::IoImpl::post()
+void IoImpl::post()
 {
-  for (smx_simcall_t const& simcall : simcalls_) {
-    switch (simcall->call) {
-      case SIMCALL_STORAGE_WRITE:
-        simcall_storage_write__set__result(simcall, surf_action_->get_cost());
-        break;
-      case SIMCALL_STORAGE_READ:
-        simcall_storage_read__set__result(simcall, surf_action_->get_cost());
-        break;
-      default:
-        break;
-    }
-  }
-
+  performed_ioops_ = surf_action_->get_cost();
   switch (surf_action_->get_state()) {
     case simgrid::kernel::resource::Action::State::FAILED:
       state_ = SIMIX_FAILED;
@@ -67,6 +65,16 @@ void simgrid::kernel::activity::IoImpl::post()
       THROW_IMPOSSIBLE;
       break;
   }
+  on_completion(this);
 
   SIMIX_io_finish(this);
 }
+/*************
+ * Callbacks *
+ *************/
+xbt::signal<void(IoImplPtr)> IoImpl::on_start;
+xbt::signal<void(IoImplPtr)> IoImpl::on_completion;
+
+} // namespace activity
+} // namespace kernel
+} // namespace simgrid