Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused type definitions.
[simgrid.git] / src / s4u / s4u_Io.cpp
1 /* Copyright (c) 2018-2019. 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 "xbt/log.h"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
12
13 namespace simgrid {
14 namespace s4u {
15
16 Io::Io(sg_storage_t storage, sg_size_t size, OpType type) : Activity(), storage_(storage), size_(size), type_(type)
17 {
18   Activity::set_remaining(size_);
19   pimpl_ = kernel::activity::IoImplPtr(new kernel::activity::IoImpl(name_, storage_->get_impl()));
20 }
21
22 Io* Io::start()
23 {
24   simix::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->start(size_, type_); });
25   state_ = State::STARTED;
26   return this;
27 }
28
29 Io* Io::cancel()
30 {
31   simgrid::simix::simcall([this] { boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->cancel(); });
32   state_ = State::CANCELED;
33   return this;
34 }
35
36 Io* Io::wait()
37 {
38   simcall_io_wait(pimpl_);
39   state_ = State::FINISHED;
40   return this;
41 }
42
43 Io* Io::wait_for(double)
44 {
45   THROW_UNIMPLEMENTED;
46 }
47
48 bool Io::test()
49 {
50   xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
51
52   if (state_ == State::FINISHED)
53     return true;
54
55   if (state_ == State::INITED)
56     this->start();
57
58   THROW_UNIMPLEMENTED;
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<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
68 }
69
70 sg_size_t Io::get_performed_ioops()
71 {
72   return simgrid::simix::simcall(
73       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
74 }
75
76 void intrusive_ptr_release(simgrid::s4u::Io* i)
77 {
78   if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
79     std::atomic_thread_fence(std::memory_order_acquire);
80     delete i;
81   }
82 }
83
84 void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
85 {
86   i->refcount_.fetch_add(1, std::memory_order_relaxed);
87 }
88 } // namespace s4u
89 } // namespace simgrid