1 /* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
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. */
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 "simgrid/simix.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
15 template class xbt::Extendable<s4u::Disk>;
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;
23 Disk* Disk::set_name(const std::string& name)
29 Disk* Disk::set_read_bandwidth(double read_bw)
31 pimpl_->set_read_bandwidth(read_bw);
35 Disk* Disk::set_write_bandwidth(double write_bw)
37 pimpl_->set_write_bandwidth(write_bw);
41 double Disk::get_read_bandwidth() const
43 return this->pimpl_->get_read_bandwidth();
46 double Disk::get_write_bandwidth() const
48 return pimpl_->get_write_bandwidth();
51 Disk* Disk::set_host(Host* host)
53 pimpl_->set_host(host);
57 Host* Disk::get_host() const
59 return pimpl_->get_host();
62 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
64 return pimpl_->get_properties();
67 const char* Disk::get_property(const std::string& key) const
69 return this->pimpl_->get_property(key);
72 void Disk::set_property(const std::string& key, const std::string& value)
74 kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
77 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
79 return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
82 IoPtr Disk::read_async(sg_size_t size)
84 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
87 sg_size_t Disk::read(sg_size_t size)
89 return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
92 IoPtr Disk::write_async(sg_size_t size)
94 return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
97 sg_size_t Disk::write(sg_size_t size)
99 return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
104 kernel::actor::simcall([this]{ pimpl_->seal(); });
105 get_host()->add_disk(this);
106 Disk::on_creation(*this);
109 } // namespace simgrid
111 /* **************************** Public C interface *************************** */
113 const char* sg_disk_get_name(const_sg_disk_t disk)
115 return disk->get_cname();
118 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
120 return disk->get_host();
123 double sg_disk_read_bandwidth(const_sg_disk_t disk)
125 return disk->get_read_bandwidth();
128 double sg_disk_write_bandwidth(const_sg_disk_t disk)
130 return disk->get_write_bandwidth();
133 sg_size_t sg_disk_read(sg_disk_t disk, sg_size_t size)
135 return disk->read(size);
137 sg_size_t sg_disk_write(sg_disk_t disk, sg_size_t size)
139 return disk->write(size);
142 void* sg_disk_get_data(const_sg_disk_t disk)
144 return disk->get_data();
147 void sg_disk_set_data(sg_disk_t disk, void* data)
149 disk->set_data(data);