Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
declare an Io::OpType enum class
[simgrid.git] / src / s4u / s4u_Io.cpp
1 /* Copyright (c) 2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Io.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "src/kernel/activity/IoImpl.hpp"
9 #include "src/simix/smx_io_private.hpp"
10 #include "xbt/log.h"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
13
14 namespace simgrid {
15 namespace s4u {
16
17 Activity* Io::start()
18 {
19   pimpl_ = simix::simcall([this] { return SIMIX_io_start(name_, size_, storage_, type_); });
20   state_ = State::STARTED;
21   return this;
22 }
23
24 Activity* Io::cancel()
25 {
26   simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
27   state_ = State::CANCELED;
28   return this;
29 }
30
31 Activity* Io::wait()
32 {
33   //  simcall_execution_wait(pimpl_);
34   state_ = State::FINISHED;
35   return this;
36 }
37
38 Activity* Io::wait(double timeout)
39 {
40   THROW_UNIMPLEMENTED;
41   return this;
42 }
43 //
44 ///** @brief Returns whether the state of the exec is finished */
45 // bool Exec::test()
46 //{
47 //  xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
48 //
49 //  if (state_ == State::FINISHED)
50 //    return true;
51 //
52 //  if (state_ == State::INITED)
53 //    this->start();
54 //
55 //  if (simcall_execution_test(pimpl_)) {
56 //    state_ = State::FINISHED;
57 //    return true;
58 //  }
59 //
60 //  return false;
61 //}
62
63 /** @brief Returns the amount of flops that remain to be done */
64 double Io::get_remaining()
65 {
66   return simgrid::simix::simcall(
67       [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
68 }
69
70 IoPtr Io::set_io_type(OpType type)
71 {
72   xbt_assert(state_ == State::INITED, "Cannot change the name of an exec after its start");
73   type_ = type;
74   return this;
75 }
76
77 // double Io::get_remaining_ratio()
78 //{
79 //  return simgrid::simix::simcall([this]() {
80 //    return boost::static_pointer_cast<simgrid::kernel::activity::IoImpl>(pimpl_)->get_remaining_ratio();
81 //  });
82 //}
83
84 void intrusive_ptr_release(simgrid::s4u::Io* e)
85 {
86   if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
87     std::atomic_thread_fence(std::memory_order_acquire);
88     delete e;
89   }
90 }
91
92 void intrusive_ptr_add_ref(simgrid::s4u::Io* e)
93 {
94   e->refcount_.fetch_add(1, std::memory_order_relaxed);
95 }
96 } // namespace s4u
97 } // namespace simgrid