From fc6fb42c354e8c1c7f6f6526c560ba858d75c027 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 12 Aug 2016 23:12:50 +0200 Subject: [PATCH 1/1] add a Mailbox::byName(std::string) function --- examples/s4u/launching/s4u_launching.cpp | 2 +- include/simgrid/s4u/mailbox.hpp | 16 ++++++++++------ src/s4u/s4u_mailbox.cpp | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/s4u/launching/s4u_launching.cpp b/examples/s4u/launching/s4u_launching.cpp index bad809870d..3c9b931486 100644 --- a/examples/s4u/launching/s4u_launching.cpp +++ b/examples/s4u/launching/s4u_launching.cpp @@ -68,7 +68,7 @@ public: /* This constructor is used when we pass parameters to the actor */ /* as with argc/argv, args[0] is the actor's name, so the first parameter is args[1] */ if (args.size() > 1) - mailbox = simgrid::s4u::Mailbox::byName(args[1].c_str()); + mailbox = simgrid::s4u::Mailbox::byName(args[1]); } void operator()() { XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->getName()); diff --git a/include/simgrid/s4u/mailbox.hpp b/include/simgrid/s4u/mailbox.hpp index 6298ad37fa..e68b46dd6f 100644 --- a/include/simgrid/s4u/mailbox.hpp +++ b/include/simgrid/s4u/mailbox.hpp @@ -32,19 +32,22 @@ XBT_PUBLIC_CLASS Mailbox { Mailbox(smx_mailbox_t mbox): pimpl_(mbox) {} -public: - smx_mailbox_t getImpl() { return pimpl_; } // FIXME: make me protected - // We don't have to manage the lifetime of mailboxes: friend void intrusive_ptr_add_ref(Mailbox*) {} friend void intrusive_ptr_release(Mailbox*) {} +public: + smx_mailbox_t getImpl() { return pimpl_; } // FIXME: make me protected + /** Get the name of that mailbox */ const char *getName(); - /** Retrieve the mailbox associated to the given string */ + /** Retrieve the mailbox associated to the given string (as a C string) */ static MailboxPtr byName(const char *name); + /** Retrieve the mailbox associated to the given string (as a C++ string) */ + static MailboxPtr byName(std::string name); + /** Returns whether the mailbox contains queued communications */ bool empty(); @@ -53,8 +56,9 @@ public: /** Declare that the specified process is a permanent receiver on that mailbox * - * It means that the communications sent to this mailbox will start flowing to its host even before he does a recv(). - * This models the real behavior of TCP and MPI communications, amongst other. + * It means that the communications sent to this mailbox will start flowing to + * its host even before he does a recv(). This models the real behavior of TCP + * and MPI communications, amongst other. */ void setReceiver(ActorPtr process); diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index cff1a5f452..6e5f18d3b6 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -34,6 +34,11 @@ MailboxPtr Mailbox::byName(const char*name) return MailboxPtr(&mbox->piface_, true); } +MailboxPtr Mailbox::byName(std::string name) +{ + return byName(name.c_str()); +} + bool Mailbox::empty() { return pimpl_->comm_queue.empty(); -- 2.20.1