}
}
+/** Execute all the tasks that are queued, e.g. `.then()` callbacks of futures. */
+bool EngineImpl::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 EngineImpl::run()
{
if (MC_record_replay_is_active()) {
#endif
}
- simix_global->execute_tasks();
+ 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());
}
}
- simix_global->execute_tasks();
+ execute_tasks();
do {
wake_all_waiting_actors();
- } while (simix_global->execute_tasks());
+ } while (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())
bool again = false;
do {
again = timer::Timer::execute_all();
- if (simix_global->execute_tasks())
+ if (execute_tasks())
again = true;
wake_all_waiting_actors();
} while (again);
#include <simgrid/s4u/Engine.hpp>
#include <simgrid/s4u/NetZone.hpp>
#include <simgrid/simix.hpp>
+#include <xbt/functional.hpp>
#include <map>
#include <string>
std::unordered_map<std::string, std::shared_ptr<resource::Model>> models_prio_;
routing::NetZoneImpl* netzone_root_ = nullptr;
+ std::vector<xbt::Task<void()>> tasks;
+ std::vector<xbt::Task<void()>> tasksTemp;
+
friend s4u::Engine;
public:
return res->second;
}
+ bool execute_tasks();
+ void add_task(xbt::Task<void()>&& t) { tasks.push_back(std::move(t)); }
void wake_all_waiting_actors() const;
void display_all_actor_status() const;
#include <simgrid/kernel/future.hpp>
-#include "src/simix/smx_private.hpp"
+#include "src/kernel/EngineImpl.hpp"
namespace simgrid {
namespace kernel {
void FutureStateBase::schedule(simgrid::xbt::Task<void()>&& job) const
{
- simix_global->tasks.push_back(std::move(job));
+ EngineImpl::get_instance()->add_task(std::move(job));
}
-}
-}
+} // namespace kernel
+} // namespace simgrid
namespace simgrid {
namespace simix {
-/** 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()) {
class Global {
public:
- bool execute_tasks();
/**
* Garbage collection
*
std::mutex mutex;
- std::vector<xbt::Task<void()>> tasks;
- std::vector<xbt::Task<void()>> tasksTemp;
-
std::vector<kernel::actor::ActorImpl*> daemons;
};
}