Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve output (consistent with similar s4u example)
[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 #include <string>
14
15 namespace simgrid {
16 namespace s4u {
17
18 /** I/O Activity, representing the asynchronous disk access.
19  *
20  * They are generated from Disk::io_init(), Disk::read() Disk::read_async(), Disk::write() and Disk::write_async().
21  */
22
23 class XBT_PUBLIC Io : public Activity {
24 public:
25   enum class OpType { READ, WRITE };
26
27 private:
28   Storage* storage_ = nullptr;
29   Disk* disk_       = nullptr;
30   sg_size_t size_   = 0;
31   OpType type_      = OpType::READ;
32   std::string name_ = "";
33   std::atomic_int_fast32_t refcount_{0};
34
35   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
36   explicit Io(sg_disk_t disk, sg_size_t size, OpType type);
37
38 public:
39 #ifndef DOXYGEN
40   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
41   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
42   friend Disk;    // Factory of IOs
43   friend Storage; // Factory of IOs
44 #endif
45
46   ~Io() = default;
47
48   Io* start() override;
49   Io* wait() override;
50   Io* wait_for(double timeout) override;
51   Io* cancel() override;
52   bool test() override;
53
54   double get_remaining() override;
55   sg_size_t get_performed_ioops();
56 };
57
58 } // namespace s4u
59 } // namespace simgrid
60
61 #endif /* SIMGRID_S4U_IO_HPP */