From 921453365eae0f6cd258bdd70cef68ad2b6865c1 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 6 Jul 2017 13:43:51 +0200 Subject: [PATCH] data is now userdata for process/actor --- src/msg/msg_process.cpp | 6 +++--- src/simix/ActorImpl.cpp | 25 ++++++++----------------- src/simix/ActorImpl.hpp | 4 +++- src/simix/libsmx.cpp | 2 +- src/smpi/smpi_global.cpp | 6 +++--- src/smpi/smpi_process.cpp | 2 +- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 14d00971f0..2cabc4796d 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -35,7 +35,7 @@ void MSG_process_cleanup_from_SIMIX(smx_actor_t smx_actor) msg_actor = (simgrid::msg::ActorExt*)SIMIX_process_self_get_data(); SIMIX_process_self_set_data(nullptr); } else { - msg_actor = (simgrid::msg::ActorExt*)smx_actor->data; + msg_actor = (simgrid::msg::ActorExt*)smx_actor->userdata; simcall_process_set_data(smx_actor, nullptr); } @@ -232,7 +232,7 @@ void* MSG_process_get_data(msg_process_t process) xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!"); /* get from SIMIX the MSG process data, and then the user data */ - simgrid::msg::ActorExt* msgExt = (simgrid::msg::ActorExt*)process->getImpl()->data; + simgrid::msg::ActorExt* msgExt = (simgrid::msg::ActorExt*)process->getImpl()->userdata; if (msgExt) return msgExt->data; else @@ -248,7 +248,7 @@ msg_error_t MSG_process_set_data(msg_process_t process, void *data) { xbt_assert(process != nullptr, "Invalid parameter: first parameter must not be nullptr!"); - static_cast(process->getImpl()->data)->data = data; + static_cast(process->getImpl()->userdata)->data = data; return MSG_OK; } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index f7d2dca74f..9cc63bbe7c 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -178,7 +178,7 @@ ActorImpl* ActorImpl::restart(ActorImpl* issuer) arg.code = code; arg.host = host; arg.kill_time = SIMIX_timer_get_date(kill_timer); - arg.data = data; + arg.data = userdata; arg.properties = nullptr; arg.auto_restart = auto_restart; @@ -258,7 +258,7 @@ void create_maestro(std::function code) maestro = new simgrid::simix::ActorImpl(); maestro->pid = simix_process_maxpid++; maestro->name = ""; - maestro->data = nullptr; + maestro->userdata = nullptr; if (not code) { maestro->context = SIMIX_context_new(std::function(), nullptr, maestro); @@ -309,7 +309,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function code, v process->pid = simix_process_maxpid++; process->name = simgrid::xbt::string(name); process->host = host; - process->data = data; + process->userdata = data; process->simcall.issuer = process; if (parent_process != nullptr) { @@ -375,7 +375,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn process->pid = simix_process_maxpid++; process->name = std::string(name); process->host = host; - process->data = data; + process->userdata = data; process->simcall.issuer = process; if (parent_process != nullptr) { @@ -645,20 +645,14 @@ void* SIMIX_process_self_get_data() if (not self) { return nullptr; } - return self->data; + return self->getUserData(); } void SIMIX_process_self_set_data(void *data) { - smx_actor_t self = SIMIX_process_self(); - - SIMIX_process_set_data(self, data); + SIMIX_process_self()->setUserData(data); } -void SIMIX_process_set_data(smx_actor_t process, void *data) -{ - process->data = data; -} /* needs to be public and without simcall because it is called by exceptions and logging events */ @@ -788,11 +782,8 @@ void SIMIX_process_yield(smx_actor_t self) SIMIX_process_on_exit_runall(self); /* Add the process to the list of process to restart, only if the host is down */ if (self->auto_restart && self->host->isOff()) { - SIMIX_host_add_auto_restart_process(self->host, self->cname(), - self->code, self->data, - SIMIX_timer_get_date(self->kill_timer), - self->properties, - self->auto_restart); + SIMIX_host_add_auto_restart_process(self->host, self->cname(), self->code, self->userdata, + SIMIX_timer_get_date(self->kill_timer), self->properties, self->auto_restart); } XBT_DEBUG("Process %s@%s is dead", self->cname(), self->host->getCname()); self->context->stop(); diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index e4517b95fe..6baac2c810 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -61,7 +61,7 @@ public: std::list comms; /* the current non-blocking communication synchros */ xbt_dict_t properties = nullptr; s_smx_simcall_t simcall; - void *data = nullptr; /* kept for compatibility, it should be replaced with moddata */ + void* userdata = nullptr; /* kept for compatibility, it should be replaced with moddata */ std::vector on_exit; /* list of functions executed when the process dies */ std::function code; @@ -110,6 +110,8 @@ public: smx_activity_t suspend(ActorImpl* issuer); void resume(); smx_activity_t sleep(double duration); + void setUserData(void* data) { userdata = data; } + void* getUserData() { return userdata; } }; } diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index e90bfa4741..47b9266843 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -229,7 +229,7 @@ int simcall_process_count() */ void simcall_process_set_data(smx_actor_t process, void *data) { - simgrid::simix::kernelImmediate(std::bind(SIMIX_process_set_data, process, data)); + simgrid::simix::kernelImmediate([process, data] { process->setUserData(data); }); } /** diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 015834fee8..4a0758da72 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -79,7 +79,7 @@ simgrid::smpi::Process* smpi_process() smx_actor_t me = SIMIX_process_self(); if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...) return nullptr; - simgrid::msg::ActorExt* msgExt = static_cast(me->data); + simgrid::msg::ActorExt* msgExt = static_cast(me->userdata); return static_cast(msgExt->data); } @@ -180,7 +180,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !"); smpi_switch_data_segment( - static_cast((static_cast(comm->src_proc->data)->data)) + static_cast((static_cast(comm->src_proc->userdata)->data)) ->index()); tmpbuff = static_cast(xbt_malloc(buff_size)); memcpy_private(tmpbuff, buff, private_blocks); @@ -190,7 +190,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){ XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment"); smpi_switch_data_segment( - static_cast((static_cast(comm->dst_proc->data)->data)) + static_cast((static_cast(comm->dst_proc->userdata)->data)) ->index()); } XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff); diff --git a/src/smpi/smpi_process.cpp b/src/smpi/smpi_process.cpp index 92d552eaad..60f576028e 100644 --- a/src/smpi/smpi_process.cpp +++ b/src/smpi/smpi_process.cpp @@ -76,7 +76,7 @@ void Process::set_data(int index, int* argc, char*** argv) instance_id_ = instance_id; index_ = index; - static_cast(SIMIX_process_self()->data)->data = this; + static_cast(SIMIX_process_self()->userdata)->data = this; if (*argc > 3) { memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2)); -- 2.20.1