Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5f2a72c9cbf86f31f2179082e098070189e146b0
[simgrid.git] / src / kernel / resource / DiskImpl.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 "DiskImpl.hpp"
7
8 #include "simgrid/s4u/Engine.hpp"
9 #include "src/kernel/EngineImpl.hpp"
10 #include "src/kernel/lmm/maxmin.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(disk_kernel, surf, "Logging specific to the disk kernel resource");
13
14 simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
15
16 namespace simgrid {
17 namespace kernel {
18 namespace resource {
19
20 /*********
21  * Model *
22  *********/
23
24 DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
25 {
26   set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
27 }
28
29 DiskModel::~DiskModel()
30 {
31   surf_disk_model = nullptr;
32 }
33
34 /************
35  * Resource *
36  ************/
37
38 DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
39                    double read_bw, double write_bw)
40     : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw)))
41 // FIXME    , piface_(name, this)
42 {
43   DiskImpl::turn_on();
44   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw, write_bw);
45   constraint_read_  = maxminSystem->constraint_new(this, read_bw);
46   constraint_write_ = maxminSystem->constraint_new(this, write_bw);
47 }
48
49 DiskImpl::~DiskImpl()
50 {
51   xbt_assert(currently_destroying_, "Don't delete Disks directly. Call destroy() instead.");
52 }
53
54 /** @brief Fire the required callbacks and destroy the object
55  *
56  * Don't delete directly a Disk, call d->destroy() instead.
57  */
58 void DiskImpl::destroy()
59 {
60   if (not currently_destroying_) {
61     currently_destroying_ = true;
62     // FIXME s4u::Storage::on_destruction(this->piface_);
63     delete this;
64   }
65 }
66
67 bool DiskImpl::is_used()
68 {
69   THROW_UNIMPLEMENTED;
70 }
71
72 void DiskImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
73 {
74   THROW_UNIMPLEMENTED;
75 }
76
77 void DiskImpl::turn_on()
78 {
79   if (not is_on()) {
80     Resource::turn_on();
81     // FIXME s4u::Storage::on_state_change(this->piface_);
82   }
83 }
84 void DiskImpl::turn_off()
85 {
86   if (is_on()) {
87     Resource::turn_off();
88     // FIXME s4u::Storage::on_state_change(this->piface_);
89   }
90 }
91
92 xbt::signal<void(DiskAction const&, kernel::resource::Action::State, kernel::resource::Action::State)>
93     DiskAction::on_state_change;
94
95 /**********
96  * Action *
97  **********/
98 void DiskAction::set_state(Action::State state)
99 {
100   Action::State old = get_state();
101   Action::set_state(state);
102   on_state_change(*this, old, state);
103 }
104 } // namespace resource
105 } // namespace kernel
106 } // namespace simgrid