1 /* Copyright (c) 2013-2018. 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::surf::StorageModel* surf_storage_model = nullptr;
23 StorageModel::StorageModel() : Model(Model::UpdateAlgo::FULL)
25 set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
28 StorageModel::~StorageModel()
30 surf_storage_model = nullptr;
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,
40 : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
43 , content_name(content_name)
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);
53 StorageImpl::~StorageImpl()
55 xbt_assert(currentlyDestroying_, "Don't delete Storages directly. Call destroy() instead.");
58 /** @brief Fire the required callbacks and destroy the object
60 * Don't delete directly a Storage, call s->destroy() instead.
62 void StorageImpl::destroy()
64 if (not currentlyDestroying_) {
65 currentlyDestroying_ = true;
66 s4u::Storage::on_destruction(this->piface_);
71 bool StorageImpl::is_used()
77 void StorageImpl::apply_event(tmgr_trace_event_t /*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*, kernel::resource::Action::State, kernel::resource::Action::State)>
97 StorageAction::on_state_change;
102 void StorageAction::set_state(Action::State state)
104 Action::State old = get_state();
105 Action::set_state(state);
106 on_state_change(this, old, state);