From d66477d0584a740d7e78942eefabc039f467453a Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 23 Apr 2016 23:01:36 +0200 Subject: [PATCH] Revert "We never use the name of the mailbox" Actually, MC use the name of the mailbox for some reason. This reverts commit cd1b6fc186f641dd5e3fb68d793c6253e1b8fcd9. --- include/simgrid/s4u/mailbox.hpp | 7 ++++--- src/s4u/s4u_mailbox.cpp | 4 ++++ src/simix/smx_network.cpp | 4 +++- src/simix/smx_network_private.h | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/simgrid/s4u/mailbox.hpp b/include/simgrid/s4u/mailbox.hpp index 2a75091cd9..4b8011c0f0 100644 --- a/include/simgrid/s4u/mailbox.hpp +++ b/include/simgrid/s4u/mailbox.hpp @@ -3,8 +3,6 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#ifdef __cplusplus - #ifndef SIMGRID_S4U_MAILBOX_HPP #define SIMGRID_S4U_MAILBOX_HPP @@ -36,18 +34,21 @@ protected: smx_mailbox_t getInferior() { return inferior_; } public: + /** Get the name of that mailbox */ + const char *getName(); /** Retrieve the mailbox associated to the given string */ static Mailbox *byName(const char *name); /** Returns whether the mailbox contains queued communications */ bool empty(); private: + std::string name_; smx_mailbox_t inferior_; static boost::unordered_map *mailboxes; }; }} // namespace simgrid::s4u -#endif +#endif /* C++ */ XBT_PUBLIC(sg_mbox_t) sg_mbox_by_name(const char*name); XBT_PUBLIC(int) sg_mbox_is_empty(sg_mbox_t mbox); diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index 6e497d85be..c057113f54 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -20,8 +20,12 @@ boost::unordered_map *s4u::Mailbox::mailboxes = ne s4u::Mailbox::Mailbox(const char*name, smx_mailbox_t inferior) { inferior_ = inferior; + name_ = name; mailboxes->insert({name, this}); } +const char *s4u::Mailbox::getName() { + return name_.c_str(); +} s4u::Mailbox *s4u::Mailbox::byName(const char*name) { s4u::Mailbox *res; try { diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 724dc20202..dcf2c73eb2 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -41,12 +41,13 @@ smx_mailbox_t SIMIX_mbox_create(const char *name) if (!mbox) { mbox = xbt_new0(s_smx_mailbox_t, 1); + mbox->name = xbt_strdup(name); mbox->comm_queue = new std::deque(); mbox->done_comm_queue = nullptr; // Allocated on need only mbox->permanent_receiver=NULL; XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name); - xbt_dict_set(mailboxes, name, mbox, NULL); + xbt_dict_set(mailboxes, mbox->name, mbox, NULL); } return mbox; } @@ -55,6 +56,7 @@ void SIMIX_mbox_free(void *data) { XBT_DEBUG("mbox free %p", data); smx_mailbox_t mbox = (smx_mailbox_t) data; + xbt_free(mbox->name); delete mbox->comm_queue; delete mbox->done_comm_queue; diff --git a/src/simix/smx_network_private.h b/src/simix/smx_network_private.h index 5c6adf8185..cc6e381ec2 100644 --- a/src/simix/smx_network_private.h +++ b/src/simix/smx_network_private.h @@ -15,6 +15,7 @@ /** @brief Rendez-vous point datatype */ typedef struct s_smx_mailbox { + char *name; std::deque *comm_queue; void *data; smx_process_t permanent_receiver; //process which the mailbox is attached to -- 2.20.1