X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e526ad06508e0193155f0591b43d7d9e9e92f6c7..77bbf3027c4240a2e833209a3a3f186589da8577:/src/surf/storage_n11.cpp?ds=sidebyside diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index d61b538940..54f284761a 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -75,33 +75,24 @@ double StorageN11Model::nextOccuringEvent(double now) void StorageN11Model::updateActionsState(double /*now*/, double delta) { - ActionList *actionSet = getRunningActionSet(); - for (ActionList::iterator it(actionSet->begin()), itNext = it, itend(actionSet->end()); it != itend; it = itNext) { - ++itNext; - - StorageAction *action = static_cast(&*it); - - double current_progress = lrint(lmm_variable_getvalue(action->getVariable()) * delta); - - action->updateRemains(current_progress); - if (action->type_ == WRITE) { - action->storage_->usedSize_ += current_progress; - action->file_->incrPosition(current_progress); - action->file_->setSize(action->file_->tell()); - - action->storage_->getContent()->erase(action->file_->cname()); - action->storage_->getContent()->insert({action->file_->cname(), action->file_->size()}); + for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) { + StorageAction& action = static_cast(*it); + ++it; // increment iterator here since the following calls to action.finish() may invalidate it + double current_progress = lrint(lmm_variable_getvalue(action.getVariable()) * delta); + action.updateRemains(current_progress); + if (action.type_ == WRITE) { + action.storage_->usedSize_ += current_progress; } - if (action->getMaxDuration() > NO_MAX_DURATION) - action->updateMaxDuration(delta); + if (action.getMaxDuration() > NO_MAX_DURATION) + action.updateMaxDuration(delta); - if (action->getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action->getVariable()) > 0 && - action->storage_->usedSize_ == action->storage_->getSize()) { - action->finish(Action::State::failed); - } else if (((action->getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) || - ((action->getMaxDuration() > NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { - action->finish(Action::State::done); + if (action.getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action.getVariable()) > 0 && + action.storage_->usedSize_ == action.storage_->getSize()) { + action.finish(Action::State::failed); + } else if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) || + ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) { + action.finish(Action::State::done); } } }