Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c9477e434d8a4d03626fdc97af2c5a14e835b0bc
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 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/Disk.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
10 #include "src/kernel/resource/DiskImpl.hpp"
11
12 namespace simgrid {
13 namespace xbt {
14 template class Extendable<s4u::Disk>;
15 } // namespace xbt
16
17 namespace s4u {
18
19 xbt::signal<void(Disk&)> Disk::on_creation;
20 xbt::signal<void(Disk const&)> Disk::on_destruction;
21 xbt::signal<void(Disk const&)> Disk::on_state_change;
22
23 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
24 {
25   return pimpl_->get_properties();
26 }
27
28 const char* Disk::get_property(const std::string& key) const
29 {
30   return this->pimpl_->get_property(key);
31 }
32
33 void Disk::set_property(const std::string& key, const std::string& value)
34 {
35   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
36 }
37
38 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
39 {
40   return IoPtr(new Io(this, size, type));
41 }
42
43 IoPtr Disk::read_async(sg_size_t size)
44 {
45   return IoPtr(io_init(size, Io::OpType::READ))->start();
46 }
47
48 sg_size_t Disk::read(sg_size_t size)
49 {
50   return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
51 }
52
53 IoPtr Disk::write_async(sg_size_t size)
54 {
55
56   return IoPtr(io_init(size, Io::OpType::WRITE)->start());
57 }
58
59 sg_size_t Disk::write(sg_size_t size)
60 {
61   return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
62 }
63
64 } // namespace s4u
65 } // namespace simgrid