From 3c8c69cc64b0da542fe7d8188ac699849090a433 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 14 Oct 2017 22:11:41 +0200 Subject: [PATCH] Constify getName()/getCname() in s4u::Actor. --- examples/s4u/actions-comm/s4u-actions-comm.cpp | 5 ++--- include/simgrid/s4u/Actor.hpp | 9 ++++++--- src/s4u/s4u_actor.cpp | 15 ++++++++++----- teshsuite/s4u/actor/actor.cpp | 2 +- .../storage_client_server.cpp | 6 +++--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples/s4u/actions-comm/s4u-actions-comm.cpp b/examples/s4u/actions-comm/s4u-actions-comm.cpp index 0be93a2963..a62e455a58 100644 --- a/examples/s4u/actions-comm/s4u-actions-comm.cpp +++ b/examples/s4u/actions-comm/s4u-actions-comm.cpp @@ -64,7 +64,7 @@ public: double clock = simgrid::s4u::Engine::getClock(); simgrid::s4u::MailboxPtr to = simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::getName() + "_" + action[2]); ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME, size, - simgrid::s4u::this_actor::getName().c_str(), to->getName()); + simgrid::s4u::this_actor::getCname(), to->getName()); to->put(payload, size); delete payload; @@ -77,8 +77,7 @@ public: simgrid::s4u::MailboxPtr from = simgrid::s4u::Mailbox::byName(std::string(action[2]) + "_" + simgrid::s4u::this_actor::getName()); - ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getName().c_str(), - from->getName()); + ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getCname(), from->getName()); from->get(); log_action(action, simgrid::s4u::Engine::getClock() - clock); } diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 4d2560d35c..210baad3b4 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -197,10 +197,10 @@ public: /** This actor will be automatically terminated when the last non-daemon process finishes **/ void daemonize(); - /** Retrieves the name of that actor as a C string */ - const char* getCname(); /** Retrieves the name of that actor as a C++ string */ - simgrid::xbt::string getName(); + const simgrid::xbt::string& getName() const; + /** Retrieves the name of that actor as a C string */ + const char* getCname() const; /** Retrieves the host on which that actor is running */ s4u::Host* getHost(); /** Retrieves the PID of that actor @@ -340,6 +340,9 @@ XBT_PUBLIC(aid_t) getPpid(); /** @brief Returns the name of the current actor. */ XBT_PUBLIC(std::string) getName(); +/** @brief Returns the name of the current actor as a C string. */ +XBT_PUBLIC(const char*) getCname(); + /** @brief Returns the name of the host on which the process is running. */ XBT_PUBLIC(Host*) getHost(); diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index c5fa2f243a..80f0c11c78 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -85,14 +85,14 @@ void Actor::daemonize() simgrid::simix::kernelImmediate([this]() { pimpl_->daemonize(); }); } -const char* Actor::getCname() +const simgrid::xbt::string& Actor::getName() const { - return this->pimpl_->name.c_str(); + return this->pimpl_->getName(); } -simgrid::xbt::string Actor::getName() +const char* Actor::getCname() const { - return this->pimpl_->name; + return this->pimpl_->getCname(); } aid_t Actor::getPid() @@ -269,7 +269,12 @@ aid_t getPpid() std::string getName() { - return SIMIX_process_self()->name; + return SIMIX_process_self()->getName(); +} + +const char* getCname() +{ + return SIMIX_process_self()->getCname(); } Host* getHost() diff --git a/teshsuite/s4u/actor/actor.cpp b/teshsuite/s4u/actor/actor.cpp index 948eca2e00..46b464fd88 100644 --- a/teshsuite/s4u/actor/actor.cpp +++ b/teshsuite/s4u/actor/actor.cpp @@ -26,7 +26,7 @@ static void master() simgrid::s4u::this_actor::getHost()->actorList(actor_list); for (auto const& actor : *actor_list) { - XBT_INFO("Actor (pid=%lu, ppid=%lu, name=%s)", actor->getPid(), actor->getPpid(), actor->getName().c_str()); + XBT_INFO("Actor (pid=%lu, ppid=%lu, name=%s)", actor->getPid(), actor->getPpid(), actor->getCname()); if (simgrid::s4u::this_actor::getPid() != actor->getPid()) actor->kill(); } diff --git a/teshsuite/s4u/storage_client_server/storage_client_server.cpp b/teshsuite/s4u/storage_client_server/storage_client_server.cpp index df64ea9a32..52a69d7817 100644 --- a/teshsuite/s4u/storage_client_server/storage_client_server.cpp +++ b/teshsuite/s4u/storage_client_server/storage_client_server.cpp @@ -27,7 +27,7 @@ static sg_size_t write_local_file(const char* dest, sg_size_t file_size) simgrid::s4u::File* file = new simgrid::s4u::File(dest, nullptr); sg_size_t written = file->write(file_size); XBT_INFO("%llu bytes on %llu bytes have been written by %s on /sd1", written, file_size, - simgrid::s4u::Actor::self()->getName().c_str()); + simgrid::s4u::Actor::self()->getCname()); delete file; return written; } @@ -38,7 +38,7 @@ static sg_size_t read_local_file(const char* src) sg_size_t file_size = file->size(); sg_size_t read = file->read(file_size); - XBT_INFO("%s has read %llu on %s", simgrid::s4u::Actor::self()->getName().c_str(), read, src); + XBT_INFO("%s has read %llu on %s", simgrid::s4u::Actor::self()->getCname(), read, src); delete file; return read; @@ -51,7 +51,7 @@ static void hsm_put(const char* remote_host, const char* src, const char* dest) sg_size_t read_size = read_local_file(src); // Send file - XBT_INFO("%s sends %llu to %s", simgrid::s4u::this_actor::getName().c_str(), read_size, remote_host); + XBT_INFO("%s sends %llu to %s", simgrid::s4u::this_actor::getCname(), read_size, remote_host); char* payload = bprintf("%s %llu", dest, read_size); simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(remote_host); mailbox->put(payload, static_cast(read_size)); -- 2.20.1