1 /* Copyright (c) 2013-2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "StorageImpl.hpp"
8 #include "surf/maxmin.hpp"
9 #include "surf_private.hpp"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
13 simgrid::surf::StorageModel* surf_storage_model = nullptr;
22 simgrid::xbt::signal<void(StorageImpl*)> storageCreatedCallbacks;
23 simgrid::xbt::signal<void(StorageImpl*)> storageDestructedCallbacks;
24 simgrid::xbt::signal<void(StorageImpl*, int, int)> storageStateChangedCallbacks; // signature: wasOn, isOn
25 simgrid::xbt::signal<void(StorageAction*, Action::State, Action::State)> storageActionStateChangedCallbacks;
27 /* List of storages */
28 std::unordered_map<std::string, StorageImpl*>* StorageImpl::storages =
29 new std::unordered_map<std::string, StorageImpl*>();
31 StorageImpl* StorageImpl::byName(std::string name)
33 if (storages->find(name) == storages->end())
35 return storages->at(name);
42 StorageModel::StorageModel() : Model()
44 maxminSystem_ = new s_lmm_system_t(true /* lazy update */);
47 StorageModel::~StorageModel()
50 surf_storage_model = nullptr;
57 StorageImpl::StorageImpl(Model* model, std::string name, lmm_system_t maxminSystem, double bread, double bwrite,
58 std::string type_id, std::string content_name, sg_size_t size, std::string attach)
59 : Resource(model, name.c_str(), maxminSystem->constraint_new(this, std::max(bread, bwrite)))
62 , content_name(content_name)
66 StorageImpl::turnOn();
67 XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
68 constraintRead_ = maxminSystem->constraint_new(this, bread);
69 constraintWrite_ = maxminSystem->constraint_new(this, bwrite);
70 storages->insert({name, this});
73 StorageImpl::~StorageImpl()
75 storageDestructedCallbacks(this);
79 bool StorageImpl::isUsed()
85 void StorageImpl::apply_event(tmgr_trace_event_t /*event*/, double /*value*/)
90 void StorageImpl::turnOn()
94 storageStateChangedCallbacks(this, 0, 1);
97 void StorageImpl::turnOff()
101 storageStateChangedCallbacks(this, 1, 0);
108 void StorageAction::setState(Action::State state)
110 Action::State old = getState();
111 Action::setState(state);
112 storageActionStateChangedCallbacks(this, old, state);