Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
jedule: obey our coding standards
[simgrid.git] / src / surf / StorageImpl.cpp
1 /* Copyright (c) 2013-2018. 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, 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.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
41     , piface_(name, this)
42     , typeId_(type_id)
43     , content_name(content_name)
44     , size_(size)
45     , attach_(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   return false;
75 }
76
77 void StorageImpl::apply_event(tmgr_trace_event_t /*event*/, double /*value*/)
78 {
79   THROW_UNIMPLEMENTED;
80 }
81
82 void StorageImpl::turn_on()
83 {
84   if (is_off()) {
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*, 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 }
109 }