Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use CRTP to factor refcounting across activity types
[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 Host* Disk::get_host()
24 {
25   return pimpl_->get_host();
26 }
27
28 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
29 {
30   return pimpl_->get_properties();
31 }
32
33 const char* Disk::get_property(const std::string& key) const
34 {
35   return this->pimpl_->get_property(key);
36 }
37
38 void Disk::set_property(const std::string& key, const std::string& value)
39 {
40   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
41 }
42
43 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
44 {
45   return IoPtr(new Io(this, size, type));
46 }
47
48 IoPtr Disk::read_async(sg_size_t size)
49 {
50   return IoPtr(io_init(size, Io::OpType::READ))->start();
51 }
52
53 sg_size_t Disk::read(sg_size_t size)
54 {
55   return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
56 }
57
58 IoPtr Disk::write_async(sg_size_t size)
59 {
60
61   return IoPtr(io_init(size, Io::OpType::WRITE)->start());
62 }
63
64 sg_size_t Disk::write(sg_size_t size)
65 {
66   return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
67 }
68
69 } // namespace s4u
70 } // namespace simgrid