return true;
}
+void EngineImpl::rm_daemon(actor::ActorImpl* actor)
+{
+ auto it = daemons_.find(actor);
+ xbt_assert(it != daemons_.end(), "The dying daemon is not a daemon after all. Please report that bug.");
+ daemons_.erase(it);
+}
+
void EngineImpl::run()
{
if (MC_record_replay_is_active()) {
} 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())
- for (auto const& dmon : simix_global->daemons) {
+ if (simix_global->process_list.size() == daemons_.size())
+ for (auto const& dmon : daemons_) {
XBT_DEBUG("Kill %s", dmon->get_cname());
simix_global->maestro_->kill(dmon);
}
simix_global->actors_to_run.size());
if (time < 0. && simix_global->actors_to_run.empty() && not simix_global->process_list.empty()) {
- if (simix_global->process_list.size() <= simix_global->daemons.size()) {
+ if (simix_global->process_list.size() <= daemons_.size()) {
XBT_CRITICAL("Oops! Daemon actors cannot do any blocking activity (communications, synchronization, etc) "
"once the simulation is over. Please fix your on_exit() functions.");
} else {
#include <xbt/functional.hpp>
#include <map>
+#include <set>
#include <string>
#include <unordered_map>
std::vector<resource::Model*> models_;
std::unordered_map<std::string, std::shared_ptr<resource::Model>> models_prio_;
routing::NetZoneImpl* netzone_root_ = nullptr;
+ std::set<kernel::actor::ActorImpl*> daemons_;
std::vector<xbt::Task<void()>> tasks;
std::vector<xbt::Task<void()>> tasksTemp;
else
return res->second;
}
+ void add_daemon(actor::ActorImpl* d) { daemons_.insert(d); }
+ void rm_daemon(actor::ActorImpl* d);
bool execute_tasks();
void add_task(xbt::Task<void()>&& t) { tasks.push_back(std::move(t)); }
#include "simgrid/Exception.hpp"
#include "simgrid/s4u/Actor.hpp"
#include "simgrid/s4u/Exec.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/activity/CommImpl.hpp"
#include "src/kernel/activity/ExecImpl.hpp"
#include "src/kernel/activity/IoImpl.hpp"
{
if (not daemon_) {
daemon_ = true;
- simix_global->daemons.push_back(this);
+ EngineImpl::get_instance()->add_daemon(this);
}
}
void ActorImpl::undaemonize()
{
if (daemon_) {
- auto& vect = simix_global->daemons;
- auto it = std::find(vect.begin(), vect.end(), this);
- xbt_assert(it != vect.end(), "The dying daemon is not a daemon after all. Please report that bug.");
- /* Don't move the whole content since we don't really care about the order */
-
- std::swap(*it, vect.back());
- vect.pop_back();
daemon_ = false;
+ EngineImpl::get_instance()->rm_daemon(this);
}
}
kernel::actor::ActorImpl* maestro_ = nullptr;
std::mutex mutex;
-
- std::vector<kernel::actor::ActorImpl*> daemons;
};
}
}