X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f89bb4bc494cb511098326ec3f18adbe0739bf26..4cce57f2ea6221443227d16439e6b55e0e252c02:/src/kernel/resource/profile/FutureEvtSet.cpp diff --git a/src/kernel/resource/profile/FutureEvtSet.cpp b/src/kernel/resource/profile/FutureEvtSet.cpp index d693df2ba5..34b4071786 100644 --- a/src/kernel/resource/profile/FutureEvtSet.cpp +++ b/src/kernel/resource/profile/FutureEvtSet.cpp @@ -1,15 +1,15 @@ -/* Copyright (c) 2004-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/kernel/resource/profile/FutureEvtSet.hpp" +#include "src/kernel/resource/Resource.hpp" #include "src/kernel/resource/profile/Event.hpp" #include "src/kernel/resource/profile/Profile.hpp" +#include -namespace simgrid { -namespace kernel { -namespace profile { +namespace simgrid::kernel::profile { simgrid::kernel::profile::FutureEvtSet future_evt_set; // FIXME: singleton antipattern @@ -25,6 +25,23 @@ FutureEvtSet::~FutureEvtSet() /** @brief Schedules an event to a future date */ void FutureEvtSet::add_event(double date, Event* evt) { + if (heap_.empty()) + s4u::Engine::on_platform_created_cb([this]() { + /* Handle the events of time = 0 right after the platform creation */ + double next_event_date; + while ((next_event_date = this->next_date()) != -1.0) { + if (next_event_date > 0) + break; + + double value = -1.0; + resource::Resource* resource = nullptr; + while (auto* event = this->pop_leq(next_event_date, &value, &resource)) { + if (value >= 0) + resource->apply_event(event, value); + } + } + }); + heap_.emplace(date, evt); } @@ -51,6 +68,4 @@ Event* FutureEvtSet::pop_leq(double date, double* value, resource::Resource** re return event; } -} // namespace profile -} // namespace kernel -} // namespace simgrid +} // namespace simgrid::kernel::profile