void MSG_host_get_process_list(msg_host_t host, xbt_dynar_t whereto)
{
xbt_assert((host != nullptr), "Invalid parameters");
- smx_actor_t actor = NULL;
- xbt_swag_foreach(actor, host->extension<simgrid::simix::Host>()->process_list) {
- msg_process_t p = actor->ciface();
+ for (auto& actor : host->extension<simgrid::simix::Host>()->process_list) {
+ msg_process_t p = actor.ciface();
xbt_dynar_push(whereto, &p);
}
}
if (issuer->host == piface_)
THROWF(vm_error, 0, "Actor %s cannot suspend the VM %s in which it runs", issuer->getCname(), piface_->getCname());
- xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
- XBT_DEBUG("suspend VM(%s), where %d processes exist", piface_->getCname(), xbt_swag_size(process_list));
+ auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+ XBT_DEBUG("suspend VM(%s), where %zu processes exist", piface_->getCname(), process_list.size());
action_->suspend();
- smx_actor_t smx_process;
- smx_actor_t smx_process_safe;
- xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
- XBT_DEBUG("suspend %s", smx_process->name.c_str());
- smx_process->suspend(issuer);
+ for (auto& smx_process : process_list) {
+ XBT_DEBUG("suspend %s", smx_process.name.c_str());
+ smx_process.suspend(issuer);
}
XBT_DEBUG("suspend all processes on the VM done done");
if (getState() != SURF_VM_STATE_SUSPENDED)
THROWF(vm_error, 0, "Cannot resume VM %s: it was not suspended", piface_->getCname());
- xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
- XBT_DEBUG("Resume VM %s, containing %d processes.", piface_->getCname(), xbt_swag_size(process_list));
+ auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+ XBT_DEBUG("Resume VM %s, containing %zu processes.", piface_->getCname(), process_list.size());
action_->resume();
- smx_actor_t smx_process;
- smx_actor_t smx_process_safe;
- xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
- XBT_DEBUG("resume %s", smx_process->getCname());
- smx_process->resume();
+ for (auto& smx_process : process_list) {
+ XBT_DEBUG("resume %s", smx_process.getCname());
+ smx_process.resume();
}
vmState_ = SURF_VM_STATE_RUNNING;
XBT_VERB("Shutting down the VM %s even if it's not running but %s", piface_->getCname(), stateName);
}
- xbt_swag_t process_list = piface_->extension<simgrid::simix::Host>()->process_list;
- XBT_DEBUG("shutdown VM %s, that contains %d processes", piface_->getCname(), xbt_swag_size(process_list));
+ auto& process_list = piface_->extension<simgrid::simix::Host>()->process_list;
+ XBT_DEBUG("shutdown VM %s, that contains %zu processes", piface_->getCname(), process_list.size());
- smx_actor_t smx_process;
- smx_actor_t smx_process_safe;
- xbt_swag_foreach_safe(smx_process, smx_process_safe, process_list) {
- XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process->getCname(),
- smx_process->host->getCname(), issuer->getCname());
- SIMIX_process_kill(smx_process, issuer);
+ for (auto& smx_process : process_list) {
+ XBT_DEBUG("kill %s@%s on behalf of %s which shutdown that VM.", smx_process.getCname(),
+ smx_process.host->getCname(), issuer->getCname());
+ SIMIX_process_kill(&smx_process, issuer);
}
setState(SURF_VM_STATE_DESTROYED);
*/
void Host::actorList(std::vector<ActorPtr>* whereto)
{
- smx_actor_t actor = NULL;
- xbt_swag_foreach(actor, this->extension<simgrid::simix::Host>()->process_list)
- {
- whereto->push_back(actor->ciface());
+ for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
+ whereto->push_back(actor.ciface());
}
}
/** Get the processes attached to the host */
void Host::getProcesses(std::vector<ActorPtr>* list)
{
- smx_actor_t actor = NULL;
- xbt_swag_foreach(actor, this->extension<simgrid::simix::Host>()->process_list) {
- list->push_back(actor->iface());
+ for (auto& actor : this->extension<simgrid::simix::Host>()->process_list) {
+ list->push_back(actor.iface());
}
}
XBT_DEBUG("%p should not be run anymore",process);
simix_global->process_list.erase(process->pid);
- if (process->host)
- xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+ if (process->host && process->host_process_list_hook.is_linked()) {
+ auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
+ list.erase(list.iterator_to(*process));
+ }
xbt_swag_insert(process, simix_global->process_to_destroy);
process->context->iwannadie = 0;
host->extension_set<simgrid::simix::Host>(new simgrid::simix::Host());
/* Add the process to its host process list */
- xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+ host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
XBT_DEBUG("Start context '%s'", process->name.c_str());
process->setProperty(kv.first, kv.second);
/* Add the process to it's host process list */
- xbt_swag_insert(process, host->extension<simgrid::simix::Host>()->process_list);
+ host->extension<simgrid::simix::Host>()->process_list.push_back(*process);
/* Now insert it in the global process list and in the process to run list */
simix_global->process_list[process->pid] = process;
void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
{
xbt_assert((process != nullptr), "Invalid parameters");
- xbt_swag_remove(process, process->host->extension<simgrid::simix::Host>()->process_list);
+ auto& list = process->host->extension<simgrid::simix::Host>()->process_list;
+ list.erase(list.iterator_to(*process));
process->host = dest;
- xbt_swag_insert(process, dest->extension<simgrid::simix::Host>()->process_list);
+ dest->extension<simgrid::simix::Host>()->process_list.push_back(*process);
}
void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t process)
#include "src/simix/popping_private.hpp"
#include "src/surf/PropertyHolder.hpp"
#include "xbt/swag.h"
+#include <boost/intrusive/list.hpp>
#include <list>
#include <map>
// TODO, replace with boost intrusive container hooks
s_xbt_swag_hookup_t synchro_hookup = { nullptr, nullptr }; /* {mutex,cond,sem}->sleeping */
- s_xbt_swag_hookup_t host_proc_hookup = { nullptr, nullptr }; /* smx_host->process_lis */
s_xbt_swag_hookup_t destroy_hookup = { nullptr, nullptr }; /* simix_global->process_to_destroy */
+ boost::intrusive::list_member_hook<> host_process_list_hook; /* simgrid::simix::Host::process_list */
aid_t pid = 0;
aid_t ppid = -1;
{
if (not Host::EXTENSION_ID.valid())
Host::EXTENSION_ID = s4u::Host::extension_create<simix::Host>();
-
- simgrid::simix::ActorImpl act;
- process_list = xbt_swag_new(xbt_swag_offset(act, host_proc_hookup));
}
Host::~Host()
{
/* All processes should be gone when the host is turned off (by the end of the simulation). */
- if (xbt_swag_size(process_list) != 0) {
+ if (not process_list.empty()) {
std::string msg = std::string("Shutting down host, but it's not empty:");
- smx_actor_t process = nullptr;
-
- xbt_swag_foreach(process, process_list) msg = msg + "\n\t" + process->name.c_str();
+ for (auto const& process : process_list)
+ msg += "\n\t" + std::string(process.getName());
SIMIX_display_process_status();
THROWF(arg_error, 0, "%s", msg.c_str());
for (auto const& arg : boot_processes)
delete arg;
boot_processes.clear();
- xbt_swag_free(process_list);
}
/** Re-starts all the actors that are marked as restartable.
h->pimpl_cpu->turnOff();
/* Clean Simulator data */
- if (xbt_swag_size(host->process_list) != 0) {
- smx_actor_t process = nullptr;
- xbt_swag_foreach(process, host->process_list) {
- SIMIX_process_kill(process, issuer);
- XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process->getCname(),
- process->host->getCname(), issuer->getCname());
+ if (not host->process_list.empty()) {
+ for (auto& process : host->process_list) {
+ SIMIX_process_kill(&process, issuer);
+ XBT_DEBUG("Killing %s@%s on behalf of %s which turned off that host.", process.getCname(),
+ process.host->getCname(), issuer->getCname());
}
}
} else {
#ifndef SIMIX_HOST_PRIVATE_HPP
#define SIMIX_HOST_PRIVATE_HPP
+#include <boost/intrusive/list.hpp>
#include <functional>
#include <map>
#include <vector>
explicit Host();
virtual ~Host();
- xbt_swag_t process_list;
+ boost::intrusive::list<ActorImpl, boost::intrusive::member_hook<ActorImpl, boost::intrusive::list_member_hook<>,
+ &ActorImpl::host_process_list_hook>>
+ process_list;
std::vector<ProcessArg*> auto_restart_processes;
std::vector<ProcessArg*> boot_processes;
}
//identify neighbours in comm
//get the indexes of all processes sharing the same simix host
- xbt_swag_t process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
+ const auto& process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
int intra_comm_size = 0;
int min_index = INT_MAX; // the minimum index will be the leader
- smx_actor_t actor = nullptr;
- xbt_swag_foreach(actor, process_list)
- {
- int index = actor->pid - 1;
-
+ for (auto const& actor : process_list) {
+ int index = actor.pid - 1;
if (this->group()->rank(index) != MPI_UNDEFINED) {
intra_comm_size++;
// the process is in the comm
XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
MPI_Group group_intra = new Group(intra_comm_size);
int i = 0;
- actor = nullptr;
- xbt_swag_foreach(actor, process_list) {
- int index = actor->pid -1;
+ for (auto const& actor : process_list) {
+ int index = actor.pid - 1;
if(this->group()->rank(index)!=MPI_UNDEFINED){
group_intra->set_mapping(index, i);
i++;