/** @brief Retrieves the name of that mailbox as a C string */
const char* get_cname() const;
- /** Retrieve the mailbox associated to the given C string */
- static MailboxPtr by_name(const char* name);
-
- /** Retrieve the mailbox associated to the given C++ string */
+ /** Retrieve the mailbox associated to the given name */
static MailboxPtr by_name(std::string name);
/** Returns whether the mailbox contains queued communications */
namespace kernel {
namespace activity {
/** @brief Returns the mailbox of that name, or nullptr */
-MailboxImpl* MailboxImpl::byNameOrNull(const char* name)
+MailboxImpl* MailboxImpl::byNameOrNull(std::string name)
{
auto mbox = mailboxes->find(name);
if (mbox != mailboxes->end())
return nullptr;
}
/** @brief Returns the mailbox of that name, newly created on need */
-MailboxImpl* MailboxImpl::byNameOrCreate(const char* name)
+MailboxImpl* MailboxImpl::byNameOrCreate(std::string name)
{
- xbt_assert(name, "Mailboxes must have a name");
/* two processes may have pushed the same mbox_create simcall at the same time */
auto m = mailboxes->find(name);
if (m == mailboxes->end()) {
smx_mailbox_t mbox = new MailboxImpl(name);
- XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name);
+ XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name.c_str());
(*mailboxes)[mbox->name_] = mbox;
return mbox;
} else
/** @brief Implementation of the simgrid::s4u::Mailbox */
class MailboxImpl {
- explicit MailboxImpl(const char* name)
+ explicit MailboxImpl(std::string name)
: piface_(this), name_(name), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE)
{
}
public:
const simgrid::xbt::string& get_name() const { return name_; }
const char* get_cname() const { return name_.c_str(); }
- static MailboxImpl* byNameOrNull(const char* name);
- static MailboxImpl* byNameOrCreate(const char* name);
+ static MailboxImpl* byNameOrNull(std::string name);
+ static MailboxImpl* byNameOrCreate(std::string name);
void setReceiver(s4u::ActorPtr actor);
void push(activity::CommImplPtr comm);
void remove(smx_activity_t activity);
return pimpl_->get_cname();
}
-MailboxPtr Mailbox::by_name(const char* name)
+MailboxPtr Mailbox::by_name(std::string name)
{
kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name);
if (mbox == nullptr) {
return MailboxPtr(&mbox->piface_, true);
}
-MailboxPtr Mailbox::by_name(std::string name)
-{
- return by_name(name.c_str());
-}
-
bool Mailbox::empty()
{
return pimpl_->comm_queue.empty();