X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/38906765bf812b1c32df889f3ce7e72bb58e1326..81a1001af43cb261b637feb5900abb38d1b09cb0:/src/surf/storage_n11.cpp diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 07146a7c09..c43bfc5908 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -68,8 +68,7 @@ StorageN11Model::StorageN11Model() : StorageModel() { XBT_DEBUG("surf_storage_model_init_internal"); - storage_running_action_set_that_does_not_need_being_checked = - xbt_swag_new(xbt_swag_offset(*action, stateHookup_)); + storage_running_action_set_that_does_not_need_being_checked = xbt_swag_new(xbt_swag_offset(*action, stateHookup_)); if (!maxminSystem_) { maxminSystem_ = lmm_system_new(storage_selective_update); } @@ -82,13 +81,11 @@ StorageN11Model::~StorageN11Model(){ #include "src/surf/xml/platf.hpp" // FIXME: move that back to the parsing area Storage *StorageN11Model::createStorage(const char* id, const char* type_id, - const char* content_name, const char* content_type, xbt_dict_t properties, - const char* attach) + const char* content_name, const char* content_type, xbt_dict_t properties, const char* attach) { xbt_assert(!surf_storage_resource_priv(surf_storage_resource_by_name(id)), - "Storage '%s' declared several times in the platform file", - id); + "Storage '%s' declared several times in the platform file", id); storage_type_t storage_type = (storage_type_t) xbt_lib_get_or_null(storage_type_lib, type_id,ROUTING_STORAGE_TYPE_LEVEL); @@ -106,14 +103,9 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id, xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage); XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s'\n\t\tproperties '%p'\n\t\tBread '%f'\n", - id, - type_id, - properties, - Bread); + id, type_id, properties, Bread); - if(!p_storageList) - p_storageList = xbt_dynar_new(sizeof(char *),nullptr); - xbt_dynar_push(p_storageList, &storage); + p_storageList.push_back(storage); return storage; } @@ -121,23 +113,15 @@ Storage *StorageN11Model::createStorage(const char* id, const char* type_id, double StorageN11Model::next_occuring_event(double /*now*/) { XBT_DEBUG("storage_share_resources"); - unsigned int i, j; - Storage *storage; - void *_write_action; - StorageAction *write_action; - double min_completion = shareResourcesMaxMin(getRunningActionSet(), - maxminSystem_, lmm_solve); + double min_completion = shareResourcesMaxMin(getRunningActionSet(), maxminSystem_, lmm_solve); double rate; // Foreach disk - xbt_dynar_foreach(p_storageList,i,storage) - { + for(auto storage: p_storageList) { rate = 0; // Foreach write action on disk - xbt_dynar_foreach(storage->p_writeActions, j, _write_action) - { - write_action = static_cast(_write_action); + for (auto write_action: storage->p_writeActions) { rate += lmm_variable_getvalue(write_action->getVariable()); } if(rate > 0) @@ -157,8 +141,7 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) ++itNext; action = static_cast(&*it); - if(action->m_type == WRITE) - { + if(action->m_type == WRITE){ // Update the disk usage // Update the file size // For each action of type write @@ -166,16 +149,14 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) delta * lmm_variable_getvalue(action->getVariable()); long int incr = current_progress; - XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, " - "incr = %ld, lrint(1) = %ld, lrint(2) = %ld", + XBT_DEBUG("%s:\n\t progress = %.2f, current_progress = %.2f, incr = %ld, lrint(1) = %ld, lrint(2) = %ld", action->p_file->name, action->progress, current_progress, incr, lrint(action->progress + current_progress), lrint(action->progress)+ incr); /* take care of rounding error accumulation */ - if (lrint(action->progress + current_progress) > - lrint(action->progress)+ incr) + if (lrint(action->progress + current_progress) > lrint(action->progress)+ incr) incr++; action->progress +=current_progress; @@ -196,20 +177,14 @@ void StorageN11Model::updateActionsState(double /*now*/, double delta) if (action->getMaxDuration() != NO_MAX_DURATION) action->updateMaxDuration(delta); - if(action->getRemainsNoUpdate() > 0 && - lmm_get_variable_weight(action->getVariable()) > 0 && - action->p_storage->m_usedSize == action->p_storage->m_size) - { + if(action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && + action->p_storage->m_usedSize == action->p_storage->m_size) { action->finish(); action->setState(Action::State::failed); - } else if ((action->getRemainsNoUpdate() <= 0) && - (lmm_get_variable_weight(action->getVariable()) > 0)) - { + } else if ((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); action->setState(Action::State::done); - } else if ((action->getMaxDuration() != NO_MAX_DURATION) && - (action->getMaxDuration() <= 0)) - { + } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); action->setState(Action::State::done); } @@ -260,17 +235,15 @@ StorageAction *StorageN11::open(const char* mount, const char* path) StorageAction *StorageN11::close(surf_file_t fd) { - char *filename = fd->name; - XBT_DEBUG("\tClose file '%s' size '%llu'", filename, fd->size); + XBT_DEBUG("\tClose file '%s' size '%llu'", fd->name, fd->size); // unref write actions from storage - void *_write_action; - StorageAction *write_action; - unsigned int i; - xbt_dynar_foreach(p_writeActions, i, _write_action) { - write_action = static_cast(_write_action); + for (auto it = p_writeActions.cbegin(); it != p_writeActions.cend();) { + StorageAction *write_action = *it; if ((write_action->p_file) == fd) { - xbt_dynar_cursor_rm(p_writeActions, &i); write_action->unref(); + it = p_writeActions.erase(it); + } else { + ++it; } } free(fd->name); @@ -304,8 +277,7 @@ StorageAction *StorageN11::write(surf_file_t fd, sg_size_t size) StorageAction *action = new StorageN11Action(getModel(), size, isOff(), this, WRITE); action->p_file = fd; - /* Substract the part of the file that might disappear from the used sized on - * the storage element */ + /* Substract the part of the file that might disappear from the used sized on the storage element */ m_usedSize -= (fd->size - fd->current_position); // If the storage is full before even starting to write if(m_usedSize==m_size) { @@ -332,16 +304,14 @@ StorageN11Action::StorageN11Action(Model *model, double cost, bool failed, Stora case STAT: break; case READ: - lmm_expand(model->getMaxminSystem(), storage->p_constraintRead, - getVariable(), 1.0); + lmm_expand(model->getMaxminSystem(), storage->p_constraintRead, getVariable(), 1.0); break; case WRITE: - lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite, - getVariable(), 1.0); + lmm_expand(model->getMaxminSystem(), storage->p_constraintWrite, getVariable(), 1.0); //TODO there is something annoying with what's below. Have to sort it out... // Action *action = this; - // xbt_dynar_push(storage->p_writeActions, &action); + // storage->p_writeActions->push_back(action); // ref(); break; }