1 /* Copyright (c) 2013-2020. 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 "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"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
14 simgrid::kernel::resource::StorageModel* surf_storage_model = nullptr;
24 StorageModel::StorageModel() : Model(Model::UpdateAlgo::FULL)
26 set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
29 StorageModel::~StorageModel()
31 surf_storage_model = nullptr;
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)))
45 , content_name_(content_name)
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);
54 StorageImpl::~StorageImpl()
56 xbt_assert(currently_destroying_, "Don't delete Storages directly. Call destroy() instead.");
59 /** @brief Fire the required callbacks and destroy the object
61 * Don't delete directly a Storage, call s->destroy() instead.
63 void StorageImpl::destroy()
65 if (not currently_destroying_) {
66 currently_destroying_ = true;
67 s4u::Storage::on_destruction(this->piface_);
72 bool StorageImpl::is_used() const
77 void StorageImpl::apply_event(kernel::profile::Event* /*event*/, double /*value*/)
82 void StorageImpl::turn_on()
86 s4u::Storage::on_state_change(this->piface_);
89 void StorageImpl::turn_off()
93 s4u::Storage::on_state_change(this->piface_);
96 xbt::signal<void(StorageAction const&, Action::State, Action::State)> StorageAction::on_state_change;
101 void StorageAction::set_state(Action::State state)
103 Action::State old = get_state();
104 Action::set_state(state);
105 on_state_change(*this, old, state);
107 } // namespace resource
108 } // namespace kernel
109 } // namespace simgrid