Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / include / simgrid / s4u / Io.hpp
1 /* Copyright (c) 2017-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 #ifndef SIMGRID_S4U_IO_HPP
7 #define SIMGRID_S4U_IO_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11
12 #include <atomic>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** I/O Activity, representing the asynchronous disk access.
18  *
19  * They are generated from Storage::io_init() or Storage::read() and Storage::write().
20  */
21
22 class XBT_PUBLIC Io : public Activity {
23 public:
24   enum class OpType { READ, WRITE };
25
26 private:
27   Storage* storage_ = nullptr;
28   sg_size_t size_   = 0;
29   OpType type_      = OpType::READ;
30   std::string name_ = "";
31   std::atomic_int_fast32_t refcount_{0};
32
33   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
34
35 public:
36   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
37   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
38   friend simgrid::s4u::Storage; // Factory of IOs
39
40   ~Io() = default;
41
42   Io* start() override;
43   Io* wait() override;
44   Io* wait_for(double timeout) override;
45   Io* cancel() override;
46   bool test() override;
47
48   double get_remaining() override;
49   sg_size_t get_performed_ioops();
50
51 #ifndef DOXYGEN
52   XBT_ATTRIB_DEPRECATED_v324("Please use Io::wait_for()") void wait(double t) override { wait_for(t); }
53 #endif
54
55 private:
56 }; // class
57 } // namespace s4u
58 } // namespace simgrid
59
60 #endif /* SIMGRID_S4U_IO_HPP */