From 815ad0c49675dd68020f3562a2aca3531d81bc80 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 14 Oct 2017 22:40:05 +0200 Subject: [PATCH] Change getName() and add getCname() in s4u::Mailbox. --- examples/s4u/actions-comm/s4u-actions-comm.cpp | 4 ++-- examples/s4u/actor-create/s4u-actor-create.cpp | 2 +- examples/s4u/app-bittorrent/s4u-peer.cpp | 12 ++++++------ .../s4u/app-masterworker/s4u-app-masterworker.cpp | 2 +- examples/s4u/app-token-ring/s4u-app-token-ring.cpp | 4 ++-- examples/s4u/dht-chord/node.cpp | 10 +++++----- include/simgrid/s4u/Mailbox.hpp | 7 +++++-- src/msg/msg_gos.cpp | 2 +- src/s4u/s4u_mailbox.cpp | 9 +++++++-- 9 files changed, 30 insertions(+), 22 deletions(-) diff --git a/examples/s4u/actions-comm/s4u-actions-comm.cpp b/examples/s4u/actions-comm/s4u-actions-comm.cpp index a62e455a58..5a1faacf53 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::getCname(), to->getName()); + simgrid::s4u::this_actor::getCname(), to->getCname()); to->put(payload, size); delete payload; @@ -77,7 +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::getCname(), from->getName()); + ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getCname(), from->getCname()); from->get(); log_action(action, simgrid::s4u::Engine::getClock() - clock); } diff --git a/examples/s4u/actor-create/s4u-actor-create.cpp b/examples/s4u/actor-create/s4u-actor-create.cpp index d83d75ac11..87530584fe 100644 --- a/examples/s4u/actor-create/s4u-actor-create.cpp +++ b/examples/s4u/actor-create/s4u-actor-create.cpp @@ -73,7 +73,7 @@ public: } void operator()() { - XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getName()); + XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getCname()); std::string* msg1 = static_cast(mailbox->get()); std::string* msg2 = static_cast(mailbox->get()); diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 8f57ee9942..3225496027 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -128,13 +128,13 @@ void Peer::sendHandshakeToAllPeers() void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size) { const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"}; - XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getName()); + XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getCname()); mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach(); } void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox) { - XBT_DEBUG("Sending a BITFIELD to %s", mailbox->getName()); + XBT_DEBUG("Sending a BITFIELD to %s", mailbox->getCname()); mailbox ->put_init(new Message(MESSAGE_BITFIELD, id, bitfield_, mailbox_), MESSAGE_BITFIELD_SIZE + BITS_TO_BYTES(FILE_PIECES)) @@ -144,7 +144,7 @@ void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox) void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length) { xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece."); - XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getName()); + XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getCname()); mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach(); } @@ -164,7 +164,7 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece) int block_index = getFirstMissingBlockFrom(piece); if (block_index != -1) { int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index); - XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getName(), piece, block_index, + XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getCname(), piece, block_index, block_length); remote_peer->mailbox_ ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE) @@ -233,7 +233,7 @@ void Peer::leech() /* Send a "handshake" message to all the peers it got (since it couldn't have gotten more than 50 peers) */ sendHandshakeToAllPeers(); - XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->getName()); + XBT_DEBUG("Starting main leech loop listening on mailbox: %s", mailbox_->getCname()); void* data = nullptr; while (simgrid::s4u::Engine::getClock() < deadline && countPieces(bitfield_) < FILE_PIECES) { @@ -299,7 +299,7 @@ void Peer::handleMessage() const char* type_names[10] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "HAVE", "BITFIELD", "REQUEST", "PIECE", "CANCEL"}; - XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->getName()); + XBT_DEBUG("Received a %s message from %s", type_names[message->type], message->return_mailbox->getCname()); auto known_peer = connected_peers.find(message->peer_id); Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second; diff --git a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp index e21badf55c..199299ae05 100644 --- a/examples/s4u/app-masterworker/s4u-app-masterworker.cpp +++ b/examples/s4u/app-masterworker/s4u-app-masterworker.cpp @@ -37,7 +37,7 @@ public: if (number_of_tasks < 10000 || i % 10000 == 0) XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(), - number_of_tasks, mailbox->getName()); + number_of_tasks, mailbox->getCname()); /* - Send the computation amount to the @ref worker */ mailbox->put(new double(comp_size), comm_size); diff --git a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp index 51d44f46ac..388e19f6fe 100644 --- a/examples/s4u/app-token-ring/s4u-app-token-ring.cpp +++ b/examples/s4u/app-token-ring/s4u-app-token-ring.cpp @@ -38,7 +38,7 @@ public: if (rank == 0) { /* The root process (rank 0) first sends the token then waits to receive it back */ - XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getName()); + XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname()); std::string msg = "Token"; neighbor_mailbox->put(&msg, task_comm_size); std::string* res = static_cast(my_mailbox->get()); @@ -46,7 +46,7 @@ public: } else { std::string* res = static_cast(my_mailbox->get()); XBT_INFO("Host \"%u\" received \"%s\"", rank, res->c_str()); - XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getName()); + XBT_INFO("Host \"%u\" send 'Token' to Host \"%s\"", rank, neighbor_mailbox->getCname()); neighbor_mailbox->put(res, task_comm_size); } } diff --git a/examples/s4u/dht-chord/node.cpp b/examples/s4u/dht-chord/node.cpp index a31877fa62..4a73c0f4e1 100644 --- a/examples/s4u/dht-chord/node.cpp +++ b/examples/s4u/dht-chord/node.cpp @@ -235,7 +235,7 @@ void Node::checkPredecessor() } // receive the answer XBT_DEBUG("Sent 'Predecessor Alive' request to %d, waiting for the answer on my mailbox '%s'", pred_id_, - message->answer_to->getName()); + message->answer_to->getCname()); simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data); try { @@ -280,7 +280,7 @@ int Node::remoteGetPredecessor(int ask_to) // receive the answer XBT_DEBUG("Sent 'Get Predecessor' request to %d, waiting for the answer on my mailbox '%s'", ask_to, - message->answer_to->getName()); + message->answer_to->getCname()); simgrid::s4u::CommPtr comm = return_mailbox->get_async(&data); try { @@ -432,7 +432,7 @@ void Node::handleMessage(ChordMessage* message) message->type = FIND_SUCCESSOR_ANSWER; message->answer_id = fingers_[0]; XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d", - message->issuer_host_name.c_str(), message->answer_to->getName(), message->request_id, + message->issuer_host_name.c_str(), message->answer_to->getCname(), message->request_id, message->answer_id); message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); } else { @@ -450,7 +450,7 @@ void Node::handleMessage(ChordMessage* message) message->type = GET_PREDECESSOR_ANSWER; message->answer_id = pred_id_; XBT_DEBUG("Sending back a 'Get Predecessor Answer' to %s via mailbox '%s': my predecessor is %d", - message->issuer_host_name.c_str(), message->answer_to->getName(), message->answer_id); + message->issuer_host_name.c_str(), message->answer_to->getCname(), message->answer_id); message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); break; @@ -488,7 +488,7 @@ void Node::handleMessage(ChordMessage* message) XBT_DEBUG("Receiving a 'Predecessor Alive' request from %s", message->issuer_host_name.c_str()); message->type = PREDECESSOR_ALIVE_ANSWER; XBT_DEBUG("Sending back a 'Predecessor Alive Answer' to %s (mailbox %s)", message->issuer_host_name.c_str(), - message->answer_to->getName()); + message->answer_to->getCname()); message->answer_to->put_init(message, 10)->detach(ChordMessage::destroy); break; diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index f7d280db98..3ca34595a0 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -120,8 +121,10 @@ public: /** private function, do not use. FIXME: make me protected */ kernel::activity::MailboxImpl* getImpl() { return pimpl_; } - /** Gets the name of that mailbox */ - const char* getName(); + /** @brief Retrieves the name of that mailbox as a C++ string */ + const simgrid::xbt::string& getName() const; + /** @brief Retrieves the name of that mailbox as a C string */ + const char* getCname() const; /** Retrieve the mailbox associated to the given C string */ static MailboxPtr byName(const char *name); diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 3846e9e4fd..d6ef1f3e4c 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -270,7 +270,7 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d /* Try to receive it by calling SIMIX network layer */ try { simcall_comm_recv(MSG_process_self()->getImpl(), mailbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, timeout, rate); - XBT_DEBUG("Got task %s from %s", (*task)->name, mailbox->getName()); + XBT_DEBUG("Got task %s from %s", (*task)->name, mailbox->getCname()); (*task)->simdata->setNotUsed(); } catch (xbt_ex& e) { diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index a3dbf166c0..32ab0bb99c 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -16,9 +16,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes"); namespace simgrid { namespace s4u { -const char* Mailbox::getName() +const simgrid::xbt::string& Mailbox::getName() const { - return pimpl_->name_.c_str(); + return pimpl_->getName(); +} + +const char* Mailbox::getCname() const +{ + return pimpl_->getCname(); } MailboxPtr Mailbox::byName(const char*name) -- 2.20.1