From: Martin Quinson Date: Mon, 24 Apr 2017 23:24:09 +0000 (+0200) Subject: introduce type aid_t for Actor's ID (ie, PID) X-Git-Tag: v3.16~311 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/82af9c443eb39b534153396598f68562ed6eac98 introduce type aid_t for Actor's ID (ie, PID) --- diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 5081b05aea..6f81a81c91 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -112,4 +112,6 @@ typedef unsigned long long sg_size_t; */ typedef long long sg_offset_t; +typedef unsigned long aid_t; + #endif diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index c158e9de9d..24f7437d11 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -207,10 +207,14 @@ public: simgrid::xbt::string name(); /** Retrieves the host on which that actor is running */ s4u::Host* host(); - /** Retrieves the PID of that actor */ - int pid(); - /** Retrieves the PPID of that actor */ - int ppid(); + /** Retrieves the PID of that actor + * + * actor_id_t is an alias for unsigned long */ + aid_t pid(); + /** Retrieves the PPID of that actor + * + * actor_id_t is an alias for unsigned long */ + aid_t ppid(); /** Suspend an actor by suspending the task on which it was waiting for the completion. */ void suspend(); @@ -246,10 +250,10 @@ public: */ void kill(); - static void kill(int pid); + static void kill(aid_t pid); /** Retrieves the actor that have the given PID (or nullptr if not existing) */ - static ActorPtr byPid(int pid); + static ActorPtr byPid(aid_t pid); /** @brief Wait for the actor to finish. * @@ -313,11 +317,11 @@ namespace this_actor { XBT_PUBLIC(Comm&) isend(MailboxPtr chan, void* payload, double simulatedSize); - /** @brief Returns the PID of the current actor. */ - XBT_PUBLIC(int) pid(); + /** @brief Returns the actor ID of the current actor (same as pid). */ + XBT_PUBLIC(aid_t) pid(); - /** @brief Returns the PPID of the current actor. */ - XBT_PUBLIC(int) ppid(); + /** @brief Returns the ancestor's actor ID of the current actor (same as ppid). */ + XBT_PUBLIC(aid_t) ppid(); /** @brief Returns the name of the current actor. */ XBT_PUBLIC(std::string) name(); diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index 5c3cf43d42..e06f54f307 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -127,7 +127,7 @@ extern int smx_context_guard_size_was_set; SG_BEGIN_DECL() XBT_PUBLIC(xbt_dynar_t) SIMIX_process_get_runnable(); -XBT_PUBLIC(smx_actor_t) SIMIX_process_from_PID(int PID); +XBT_PUBLIC(smx_actor_t) SIMIX_process_from_PID(aid_t PID); XBT_PUBLIC(xbt_dynar_t) SIMIX_processes_as_dynar(); /* parallelism */ diff --git a/src/mc/mc_base.cpp b/src/mc/mc_base.cpp index cc57a3cc8e..edcf150249 100644 --- a/src/mc/mc_base.cpp +++ b/src/mc/mc_base.cpp @@ -70,7 +70,7 @@ void wait_for_requests(void) } #if HAVE_MC xbt_dynar_reset(simix_global->actors_vector); - for (std::pair kv : simix_global->process_list) { + for (std::pair kv : simix_global->process_list) { xbt_dynar_push_as(simix_global->actors_vector, smx_actor_t, kv.second); } #endif diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 96ec0750ef..bbed1a8a8d 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -77,12 +77,12 @@ simgrid::xbt::string Actor::name() return this->pimpl_->name; } -int Actor::pid() +aid_t Actor::pid() { return this->pimpl_->pid; } -int Actor::ppid() +aid_t Actor::ppid() { return this->pimpl_->ppid; } @@ -111,7 +111,8 @@ double Actor::killTime() return simcall_process_get_kill_time(pimpl_); } -void Actor::kill(int pid) { +void Actor::kill(aid_t pid) +{ smx_actor_t process = SIMIX_process_from_PID(pid); if(process != nullptr) { simcall_process_kill(process); @@ -132,7 +133,7 @@ void Actor::kill() { // ***** Static functions ***** -ActorPtr Actor::byPid(int pid) +ActorPtr Actor::byPid(aid_t pid) { smx_actor_t process = SIMIX_process_from_PID(pid); if (process != nullptr) @@ -209,12 +210,12 @@ Comm& irecv(MailboxPtr chan, void** data) return Comm::recv_async(chan, data); } -int pid() +aid_t pid() { return SIMIX_process_self()->pid; } -int ppid() +aid_t ppid() { return SIMIX_process_self()->ppid; } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 43944d041a..606bece0b0 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -866,7 +866,7 @@ xbt_dynar_t SIMIX_process_get_runnable() /** * \brief Returns the process from PID. */ -smx_actor_t SIMIX_process_from_PID(int PID) +smx_actor_t SIMIX_process_from_PID(aid_t PID) { if (simix_global->process_list.find(PID) == simix_global->process_list.end()) return nullptr; diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index 9e4930deac..906c4cd274 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -40,8 +40,8 @@ public: 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 */ - unsigned long pid = 0; - unsigned long ppid = -1; + aid_t pid = 0; + aid_t ppid = -1; simgrid::xbt::string name; const char* cname() { return name.c_str(); } s4u::Host* host = nullptr; /* the host on which the process is running */ @@ -56,7 +56,7 @@ public: sg_host_t new_host = nullptr; /* if not null, the host on which the process must migrate to */ smx_activity_t waiting_synchro = nullptr; /* the current blocking synchro if any */ - std::list comms ; /* the current non-blocking communication synchros */ + 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 */ diff --git a/src/simix/smx_private.h b/src/simix/smx_private.h index 6999488aab..9ec2107dcc 100644 --- a/src/simix/smx_private.h +++ b/src/simix/smx_private.h @@ -21,7 +21,7 @@ public: smx_context_factory_t context_factory = nullptr; xbt_dynar_t process_to_run = nullptr; xbt_dynar_t process_that_ran = nullptr; - std::map process_list; + std::map process_list; #if HAVE_MC /* MCer cannot read the std::map above in the remote process, so we copy the info it needs in a dynar. * FIXME: This is supposed to be a temporary hack. diff --git a/teshsuite/s4u/actor/actor.cpp b/teshsuite/s4u/actor/actor.cpp index d7a86285ac..3be9b1239e 100644 --- a/teshsuite/s4u/actor/actor.cpp +++ b/teshsuite/s4u/actor/actor.cpp @@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example") static void worker() { simgrid::s4u::this_actor::sleep_for(.5); - XBT_INFO("Worker started (PID:%d, PPID:%d)", simgrid::s4u::this_actor::pid(), simgrid::s4u::this_actor::ppid()); + XBT_INFO("Worker started (PID:%lu, PPID:%lu)", simgrid::s4u::this_actor::pid(), simgrid::s4u::this_actor::ppid()); while (1) { XBT_INFO("Plop i am %ssuspended", simgrid::s4u::this_actor::isSuspended() ? "" : "not "); simgrid::s4u::this_actor::sleep_for(1); @@ -25,7 +25,7 @@ static void master() simgrid::s4u::this_actor::host()->actorList(actor_list); for (auto actor : *actor_list) { - XBT_INFO("Actor (pid=%d, ppid=%d, name=%s)", actor->pid(), actor->ppid(), actor->name().c_str()); + XBT_INFO("Actor (pid=%lu, ppid=%lu, name=%s)", actor->pid(), actor->ppid(), actor->name().c_str()); if (simgrid::s4u::this_actor::pid() != actor->pid()) actor->kill(); } @@ -34,16 +34,16 @@ static void master() simgrid::s4u::Actor::createActor("worker from master", simgrid::s4u::this_actor::host(), worker); simgrid::s4u::this_actor::sleep_for(2); - XBT_INFO("Suspend Actor (pid=%d)", actor->pid()); + XBT_INFO("Suspend Actor (pid=%lu)", actor->pid()); actor->suspend(); - XBT_INFO("Actor (pid=%d) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); + XBT_INFO("Actor (pid=%lu) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); simgrid::s4u::this_actor::sleep_for(2); - XBT_INFO("Resume Actor (pid=%d)", actor->pid()); + XBT_INFO("Resume Actor (pid=%lu)", actor->pid()); actor->resume(); - XBT_INFO("Actor (pid=%d) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); + XBT_INFO("Actor (pid=%lu) is %ssuspended", actor->pid(), actor->isSuspended() ? "" : "not "); simgrid::s4u::this_actor::sleep_for(2); actor->kill();