Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
65421f45be0529840e039057ccb87a47867c2c52
[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 #include <string>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_io, s4u_activity, "S4U asynchronous IOs");
14
15 namespace simgrid {
16 namespace s4u {
17
18 Activity* Io::start()
19 {
20   Activity::set_remaining(size_);
21   pimpl_ = simix::simcall([this] {
22     return boost::static_pointer_cast<kernel::activity::IoImpl>(SIMIX_io_start(name_, size_, storage_, type_));
23   });
24   state_ = State::STARTED;
25   return this;
26 }
27
28 Activity* Io::cancel()
29 {
30   simgrid::simix::simcall([this] { dynamic_cast<kernel::activity::IoImpl*>(pimpl_.get())->cancel(); });
31   state_ = State::CANCELED;
32   return this;
33 }
34
35 Activity* Io::wait()
36 {
37   simcall_io_wait(pimpl_);
38   state_ = State::FINISHED;
39   return this;
40 }
41
42 Activity* Io::wait(double timeout)
43 {
44   THROW_UNIMPLEMENTED;
45   return this;
46 }
47
48 /** @brief Returns the amount of flops that remain to be done */
49 double Io::get_remaining()
50 {
51   return simgrid::simix::simcall(
52       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_remaining(); });
53 }
54
55 sg_size_t Io::get_performed_ioops()
56 {
57   return simgrid::simix::simcall(
58       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
59 }
60
61 void intrusive_ptr_release(simgrid::s4u::Io* i)
62 {
63   if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
64     std::atomic_thread_fence(std::memory_order_acquire);
65     delete i;
66   }
67 }
68
69 void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
70 {
71   i->refcount_.fetch_add(1, std::memory_order_relaxed);
72 }
73 } // namespace s4u
74 } // namespace simgrid