From 6f7642fad90f7489b4ab88737a190f61fcec491a Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 5 Apr 2019 11:53:49 +0200 Subject: [PATCH] objectify SIMIX_execute_tasks --- src/simix/smx_global.cpp | 55 ++++++++++++++++++--------------------- src/simix/smx_private.hpp | 1 + 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index d47121d289..4b132db5d6 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -138,6 +138,28 @@ void Timer::remove() delete this; } +/** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */ +bool Global::execute_tasks() +{ + xbt_assert(tasksTemp.empty()); + + if (tasks.empty()) + return false; + + do { + // We don't want the callbacks to modify the vector we are iterating over: + tasks.swap(tasksTemp); + + // Execute all the queued tasks: + for (auto& task : tasksTemp) + task(); + + tasksTemp.clear(); + } while (not tasks.empty()); + + return true; +} + void Global::empty_trash() { while (not actors_to_destroy.empty()) { @@ -346,31 +368,6 @@ static bool SIMIX_execute_timers() return result; } -/** Execute all the tasks that are queued - * - * e.g. `.then()` callbacks of futures. - **/ -static bool SIMIX_execute_tasks() -{ - xbt_assert(simix_global->tasksTemp.empty()); - - if (simix_global->tasks.empty()) - return false; - - do { - // We don't want the callbacks to modify the vector we are iterating over: - simix_global->tasks.swap(simix_global->tasksTemp); - - // Execute all the queued tasks: - for (auto& task : simix_global->tasksTemp) - task(); - - simix_global->tasksTemp.clear(); - } while (not simix_global->tasks.empty()); - - return true; -} - /** * @ingroup SIMIX_API * @brief Run the main simulation loop. @@ -397,7 +394,7 @@ void SIMIX_run() #endif } - SIMIX_execute_tasks(); + simix_global->execute_tasks(); while (not simix_global->actors_to_run.empty()) { XBT_DEBUG("New Sub-Schedule Round; size(queue)=%zu", simix_global->actors_to_run.size()); @@ -473,10 +470,10 @@ void SIMIX_run() } } - SIMIX_execute_tasks(); + simix_global->execute_tasks(); do { SIMIX_wake_processes(); - } while (SIMIX_execute_tasks()); + } while (simix_global->execute_tasks()); /* If only daemon processes remain, cancel their actions, mark them to die and reschedule them */ if (simix_global->process_list.size() == simix_global->daemons.size()) @@ -501,7 +498,7 @@ void SIMIX_run() bool again = false; do { again = SIMIX_execute_timers(); - if (SIMIX_execute_tasks()) + if (simix_global->execute_tasks()) again = true; SIMIX_wake_processes(); } while (again); diff --git a/src/simix/smx_private.hpp b/src/simix/smx_private.hpp index d6a15bb23b..c26de3558a 100644 --- a/src/simix/smx_private.hpp +++ b/src/simix/smx_private.hpp @@ -24,6 +24,7 @@ class Global { friend XBT_PUBLIC bool simgrid::s4u::this_actor::is_maestro(); public: + bool execute_tasks(); /** * Garbage collection * -- 2.20.1