Logo AND Algorithmique Numérique Distribuée

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