X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/76081077f259960acb8a8624359ad2aa5c32ab46..f9b13d923d31bb0336aeeaab6d5b7ba33812f3f7:/src/kernel/timer/Timer.cpp diff --git a/src/kernel/timer/Timer.cpp b/src/kernel/timer/Timer.cpp index 9c4123280a..5cc19ee376 100644 --- a/src/kernel/timer/Timer.cpp +++ b/src/kernel/timer/Timer.cpp @@ -1,10 +1,11 @@ -/* Copyright (c) 2021. The SimGrid Team. +/* Copyright (c) 2021-2022. 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 "simgrid/kernel/Timer.hpp" +#include +#include namespace simgrid { namespace kernel { @@ -24,6 +25,21 @@ void Timer::remove() delete this; } +/** Handle any pending timer. Returns if something was actually run. */ +bool Timer::execute_all() +{ + bool result = false; + while (not kernel_timers().empty() && s4u::Engine::get_clock() >= kernel_timers().top().first) { + result = true; + // FIXME: make the timers being real callbacks (i.e. provide dispatchers that read and expand the args) + Timer* timer = kernel_timers().top().second; + kernel_timers().pop(); + timer->callback(); + delete timer; + } + return result; +} + } // namespace timer } // namespace kernel } // namespace simgrid