-/********************************* SIMIX **************************************/
-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()) {
- kernel::actor::ActorImpl* actor = &actors_to_destroy.front();
- actors_to_destroy.pop_front();
- XBT_DEBUG("Getting rid of %s (refcount: %d)", actor->get_cname(), actor->get_refcount());
- intrusive_ptr_release(actor);
- }
-#if SIMGRID_HAVE_MC
- xbt_dynar_reset(dead_actors_vector);
-#endif
-}
-/**
- * @brief Executes the actors in actors_to_run.
- *
- * The actors in actors_to_run are run (in parallel if possible). On exit, actors_to_run is empty, and actors_that_ran
- * contains the list of actors that just ran. The two lists are swapped so, be careful when using them before and after
- * a call to this function.
- */
-void Global::run_all_actors()
-{
- simix_global->context_factory->run_all();
-
- actors_to_run.swap(actors_that_ran);
- actors_to_run.clear();
-}
-
-/** Wake up all actors waiting for a Surf action to finish */
-void Global::wake_all_waiting_actors() const
-{
- for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
- XBT_DEBUG("Handling the failed actions (if any)");
- while (auto* action = model->extract_failed_action()) {
- XBT_DEBUG(" Handling Action %p", action);
- if (action->get_activity() != nullptr)
- kernel::activity::ActivityImplPtr(action->get_activity())->post();
- }
- XBT_DEBUG("Handling the terminated actions (if any)");
- while (auto* action = model->extract_done_action()) {
- XBT_DEBUG(" Handling Action %p", action);
- if (action->get_activity() == nullptr)
- XBT_DEBUG("probably vcpu's action %p, skip", action);
- else
- kernel::activity::ActivityImplPtr(action->get_activity())->post();
- }
- }
-}
-
-void Global::display_all_actor_status() const
-{
- XBT_INFO("%zu actors are still running, waiting for something.", process_list.size());
- /* List the actors and their state */
- XBT_INFO("Legend of the following listing: \"Actor <pid> (<name>@<host>): <status>\"");
- for (auto const& kv : process_list) {
- kernel::actor::ActorImpl* actor = kv.second;
-
- if (actor->waiting_synchro_) {
- const char* synchro_description = "unknown";
-
- if (boost::dynamic_pointer_cast<kernel::activity::ExecImpl>(actor->waiting_synchro_) != nullptr)
- synchro_description = "execution";
-
- if (boost::dynamic_pointer_cast<kernel::activity::CommImpl>(actor->waiting_synchro_) != nullptr)
- synchro_description = "communication";
-
- if (boost::dynamic_pointer_cast<kernel::activity::SleepImpl>(actor->waiting_synchro_) != nullptr)
- synchro_description = "sleeping";
-
- if (boost::dynamic_pointer_cast<kernel::activity::RawImpl>(actor->waiting_synchro_) != nullptr)
- synchro_description = "synchronization";
-
- if (boost::dynamic_pointer_cast<kernel::activity::IoImpl>(actor->waiting_synchro_) != nullptr)
- synchro_description = "I/O";
-
- XBT_INFO("Actor %ld (%s@%s): waiting for %s activity %#zx (%s) in state %d to finish", actor->get_pid(),
- actor->get_cname(), actor->get_host()->get_cname(), synchro_description,
- (xbt_log_no_loc ? (size_t)0xDEADBEEF : (size_t)actor->waiting_synchro_.get()),
- actor->waiting_synchro_->get_cname(), (int)actor->waiting_synchro_->state_);
- } else {
- XBT_INFO("Actor %ld (%s@%s) simcall %s", actor->get_pid(), actor->get_cname(), actor->get_host()->get_cname(),
- SIMIX_simcall_name(actor->simcall_));
- }
- }
-}
-
-} // namespace simix
-} // namespace simgrid
-