Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't use pass-by-value for large parameters.
[simgrid.git] / src / surf / StorageImpl.cpp
1 /* Copyright (c) 2013-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 "StorageImpl.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "src/kernel/EngineImpl.hpp"
9 #include "src/kernel/lmm/maxmin.hpp"
10 #include "surf_private.hpp"
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
13
14 simgrid::surf::StorageModel* surf_storage_model = nullptr;
15
16 namespace simgrid {
17 namespace surf {
18
19 /*********
20  * Model *
21  *********/
22
23 StorageModel::StorageModel() : Model(Model::UpdateAlgo::FULL)
24 {
25   set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
26 }
27
28 StorageModel::~StorageModel()
29 {
30   surf_storage_model = nullptr;
31 }
32
33 /************
34  * Resource *
35  ************/
36
37 StorageImpl::StorageImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
38                          double bread, double bwrite, std::string type_id, std::string content_name, sg_size_t size,
39                          std::string attach)
40     : Resource(model, name, maxminSystem->constraint_new(this, std::max(bread, bwrite)))
41     , piface_(name, this)
42     , typeId_(std::move(type_id))
43     , content_name(std::move(content_name))
44     , size_(size)
45     , attach_(std::move(attach))
46 {
47   StorageImpl::turn_on();
48   XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
49   constraintRead_  = maxminSystem->constraint_new(this, bread);
50   constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
51 }
52
53 StorageImpl::~StorageImpl()
54 {
55   xbt_assert(currentlyDestroying_, "Don't delete Storages directly. Call destroy() instead.");
56 }
57
58 /** @brief Fire the required callbacks and destroy the object
59  *
60  * Don't delete directly a Storage, call s->destroy() instead.
61  */
62 void StorageImpl::destroy()
63 {
64   if (not currentlyDestroying_) {
65     currentlyDestroying_ = true;
66     s4u::Storage::on_destruction(this->piface_);
67     delete this;
68   }
69 }
70
71 bool StorageImpl::is_used()
72 {
73   THROW_UNIMPLEMENTED;
74 }
75
76 void StorageImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
77 {
78   THROW_UNIMPLEMENTED;
79 }
80
81 void StorageImpl::turn_on()
82 {
83   if (not is_on()) {
84     Resource::turn_on();
85     s4u::Storage::on_state_change(this->piface_);
86   }
87 }
88 void StorageImpl::turn_off()
89 {
90   if (is_on()) {
91     Resource::turn_off();
92     s4u::Storage::on_state_change(this->piface_);
93   }
94 }
95 xbt::signal<void(StorageAction*, kernel::resource::Action::State, kernel::resource::Action::State)>
96     StorageAction::on_state_change;
97
98 /**********
99  * Action *
100  **********/
101 void StorageAction::set_state(Action::State state)
102 {
103   Action::State old = get_state();
104   Action::set_state(state);
105   on_state_change(this, old, state);
106 }
107 }
108 }