Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4fb6b9ff49a98c42ab5ce219746037762af06f8f
[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 simgrid::s4u::Storage::read() and simgrid::s4u::Storage::write().
21  */
22
23 class XBT_PUBLIC Io : public Activity {
24 public:
25   friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
26   friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
27   friend simgrid::s4u::Storage; // Factory of IOs
28   enum class OpType { READ, WRITE };
29
30 private:
31   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
32
33 public:
34   ~Io() = default;
35
36   Io* start() override;
37   Io* wait() override;
38   Io* wait_for(double timeout) override;
39   Io* cancel() override;
40   bool test() override;
41
42   double get_remaining() override;
43   sg_size_t get_performed_ioops();
44
45 #ifndef DOXYGEN
46   XBT_ATTRIB_DEPRECATED_v324("Please use Io::wait_for()") void wait(double t) override { wait_for(t); }
47 #endif
48
49 private:
50   sg_storage_t storage_ = nullptr;
51   sg_size_t size_       = 0;
52   OpType type_          = OpType::READ;
53   std::string name_     = "";
54   std::atomic_int_fast32_t refcount_{0};
55 }; // class
56 }
57 }; // Namespace simgrid::s4u
58
59 #endif /* SIMGRID_S4U_IO_HPP */