1 /* Copyright (c) 2021. 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 <simgrid/kernel/Timer.hpp>
8 #include <simgrid/s4u/Engine.hpp>
9 #include <simgrid/simix.h>
15 Timer* Timer::set(double date, xbt::Task<void()>&& callback)
17 auto* timer = new Timer(date, std::move(callback));
18 timer->handle_ = kernel_timers().emplace(std::make_pair(date, timer));
22 /** @brief cancels a timer that was added earlier */
25 kernel_timers().erase(handle_);
29 /** Handle any pending timer. Returns if something was actually run. */
30 bool Timer::execute_all()
33 while (not kernel_timers().empty() && s4u::Engine::get_clock() >= kernel_timers().top().first) {
35 // FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args)
36 Timer* timer = kernel_timers().top().second;
37 kernel_timers().pop();
46 } // namespace simgrid