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/simix.h>
14 Timer* Timer::set(double date, xbt::Task<void()>&& callback)
16 auto* timer = new Timer(date, std::move(callback));
17 timer->handle_ = kernel_timers().emplace(std::make_pair(date, timer));
21 /** @brief cancels a timer that was added earlier */
24 kernel_timers().erase(handle_);
28 /** Handle any pending timer. Returns if something was actually run. */
29 bool Timer::execute_all()
32 while (not kernel_timers().empty() && SIMIX_get_clock() >= kernel_timers().top().first) {
34 // FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args)
35 Timer* timer = kernel_timers().top().second;
36 kernel_timers().pop();
45 } // namespace simgrid