From 40e0bf5686dc6da940c2dfe33c2e8b4824fefb8f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 13 Jul 2018 22:07:15 +0200 Subject: [PATCH] MailboxImpl: snake_case and follow our coding standards --- src/kernel/activity/MailboxImpl.cpp | 16 ++++++++-------- src/kernel/activity/MailboxImpl.hpp | 22 ++++++++++++++-------- src/s4u/s4u_Mailbox.cpp | 16 ++++++++-------- src/simix/smx_network.cpp | 28 ++++++++++++++-------------- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index ebf615ef52..f519fa224d 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -25,7 +25,7 @@ namespace simgrid { namespace kernel { namespace activity { /** @brief Returns the mailbox of that name, or nullptr */ -MailboxImpl* MailboxImpl::byNameOrNull(std::string name) +MailboxImpl* MailboxImpl::by_name_or_null(std::string name) { auto mbox = mailboxes->find(name); if (mbox != mailboxes->end()) @@ -34,7 +34,7 @@ MailboxImpl* MailboxImpl::byNameOrNull(std::string name) return nullptr; } /** @brief Returns the mailbox of that name, newly created on need */ -MailboxImpl* MailboxImpl::byNameOrCreate(std::string name) +MailboxImpl* MailboxImpl::by_name_or_create(std::string name) { /* two processes may have pushed the same mbox_create simcall at the same time */ auto m = mailboxes->find(name); @@ -49,12 +49,12 @@ MailboxImpl* MailboxImpl::byNameOrCreate(std::string name) /** @brief set the receiver of the mailbox to allow eager sends * \param actor The receiving dude */ -void MailboxImpl::setReceiver(s4u::ActorPtr actor) +void MailboxImpl::set_receiver(s4u::ActorPtr actor) { if (actor != nullptr) - this->permanent_receiver = actor.get()->get_impl(); + this->permanent_receiver_ = actor->get_impl(); else - this->permanent_receiver = nullptr; + this->permanent_receiver_ = nullptr; } /** @brief Pushes a communication activity into a mailbox * @param comm What to add @@ -62,7 +62,7 @@ void MailboxImpl::setReceiver(s4u::ActorPtr actor) void MailboxImpl::push(activity::CommImplPtr comm) { comm->mbox = this; - this->comm_queue.push_back(std::move(comm)); + this->comm_queue_.push_back(std::move(comm)); } /** @brief Removes a communication activity from a mailbox @@ -76,9 +76,9 @@ void MailboxImpl::remove(smx_activity_t activity) xbt_assert(comm->mbox == this, "Comm %p is in mailbox %s, not mailbox %s", comm.get(), (comm->mbox ? comm->mbox->get_cname() : "(null)"), this->get_cname()); comm->mbox = nullptr; - for (auto it = this->comm_queue.begin(); it != this->comm_queue.end(); it++) + for (auto it = this->comm_queue_.begin(); it != this->comm_queue_.end(); it++) if (*it == comm) { - this->comm_queue.erase(it); + this->comm_queue_.erase(it); return; } xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname()); diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index b965ea559b..f7a3357018 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -21,25 +21,31 @@ namespace activity { /** @brief Implementation of the simgrid::s4u::Mailbox */ class MailboxImpl { + friend s4u::Mailbox; + explicit MailboxImpl(std::string name) - : piface_(this), name_(name), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE) + : 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(std::string name); - static MailboxImpl* byNameOrCreate(std::string name); - void setReceiver(s4u::ActorPtr actor); + static MailboxImpl* by_name_or_null(std::string name); + static MailboxImpl* by_name_or_create(std::string name); + void set_receiver(s4u::ActorPtr actor); void push(activity::CommImplPtr comm); void remove(smx_activity_t activity); - simgrid::s4u::Mailbox piface_; // Our interface + +private: + simgrid::s4u::Mailbox piface_; simgrid::xbt::string name_; - simgrid::kernel::actor::ActorImplPtr permanent_receiver; // actor to which the mailbox is attached - boost::circular_buffer_space_optimized comm_queue; - boost::circular_buffer_space_optimized done_comm_queue; // messages already received in the permanent receive mode +public: + simgrid::kernel::actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached + boost::circular_buffer_space_optimized comm_queue_; + boost::circular_buffer_space_optimized + done_comm_queue_; // messages already received in the permanent receive mode }; } } diff --git a/src/s4u/s4u_Mailbox.cpp b/src/s4u/s4u_Mailbox.cpp index 03c12aa6c4..a810de4770 100644 --- a/src/s4u/s4u_Mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -26,39 +26,39 @@ const char* Mailbox::get_cname() const MailboxPtr Mailbox::by_name(std::string name) { - kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name); + kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::by_name_or_null(name); if (mbox == nullptr) { - mbox = simix::simcall([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); }); + mbox = simix::simcall([name] { return kernel::activity::MailboxImpl::by_name_or_create(name); }); } return MailboxPtr(&mbox->piface_, true); } bool Mailbox::empty() { - return pimpl_->comm_queue.empty(); + return pimpl_->comm_queue_.empty(); } bool Mailbox::listen() { - return not this->empty() || (pimpl_->permanent_receiver && not pimpl_->done_comm_queue.empty()); + return not this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty()); } smx_activity_t Mailbox::front() { - return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front(); + return pimpl_->comm_queue_.empty() ? nullptr : pimpl_->comm_queue_.front(); } void Mailbox::set_receiver(ActorPtr actor) { - simix::simcall([this, actor]() { this->pimpl_->setReceiver(actor); }); + simix::simcall([this, actor]() { this->pimpl_->set_receiver(actor); }); } /** @brief get the receiver (process associated to the mailbox) */ ActorPtr Mailbox::get_receiver() { - if (pimpl_->permanent_receiver == nullptr) + if (pimpl_->permanent_receiver_ == nullptr) return ActorPtr(); - return pimpl_->permanent_receiver->iface(); + return pimpl_->permanent_receiver_->iface(); } CommPtr Mailbox::put_init() diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 8e1cfdb4f0..da781c865e 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -98,16 +98,16 @@ XBT_PRIVATE smx_activity_t simcall_HANDLER_comm_isend( * * If it is not found then push our communication into the rendez-vous point */ simgrid::kernel::activity::CommImplPtr other_comm = - _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true); + _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true); if (not other_comm) { other_comm = std::move(this_comm); - if (mbox->permanent_receiver != nullptr) { + if (mbox->permanent_receiver_ != nullptr) { //this mailbox is for small messages, which have to be sent right now other_comm->state_ = SIMIX_READY; - other_comm->dst_proc=mbox->permanent_receiver.get(); - mbox->done_comm_queue.push_back(other_comm); + other_comm->dst_proc = mbox->permanent_receiver_.get(); + mbox->done_comm_queue_.push_back(other_comm); XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, other_comm.get()); }else{ @@ -181,11 +181,11 @@ SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void* dst_buff, size_ simgrid::kernel::activity::CommImplPtr other_comm; //communication already done, get it inside the list of completed comms - if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) { + if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) { XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication"); //find a match in the list of already received comms - other_comm = _find_matching_comm(&mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro, + other_comm = _find_matching_comm(&mbox->done_comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro, /*remove_matching*/ true); //if not found, assume the receiver came first, register it to the mailbox in the classical way if (not other_comm) { @@ -207,11 +207,11 @@ SIMIX_comm_irecv(smx_actor_t dst_proc, smx_mailbox_t mbox, void* dst_buff, size_ * ourself so that the other side also gets a chance of choosing if it wants to match with us. * * If it is not found then push our communication into the rendez-vous point */ - other_comm = _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro, + other_comm = _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro, /*remove_matching*/ true); if (other_comm == nullptr) { - XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue.size()); + XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue_.size()); other_comm = std::move(this_synchro); mbox->push(other_comm); } else { @@ -253,7 +253,7 @@ smx_activity_t simcall_HANDLER_comm_iprobe(smx_simcall_t simcall, smx_mailbox_t smx_activity_t SIMIX_comm_iprobe(smx_actor_t dst_proc, smx_mailbox_t mbox, int type, simix_match_func_t match_fun, void* data) { - XBT_DEBUG("iprobe from %p %p", mbox, &mbox->comm_queue); + XBT_DEBUG("iprobe from %p %p", mbox, &mbox->comm_queue_); simgrid::kernel::activity::CommImplPtr this_comm; int smx_type; if(type == 1){ @@ -264,15 +264,15 @@ smx_activity_t SIMIX_comm_iprobe(smx_actor_t dst_proc, smx_mailbox_t mbox, int t smx_type = SIMIX_COMM_SEND; } smx_activity_t other_synchro=nullptr; - if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) { + if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) { XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something"); - other_synchro = _find_matching_comm(&mbox->done_comm_queue, - (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false); + other_synchro = _find_matching_comm(&mbox->done_comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data, + this_comm, /*remove_matching*/ false); } if (not other_synchro) { XBT_DEBUG("check if we have more luck in the normal mailbox"); - other_synchro = _find_matching_comm(&mbox->comm_queue, - (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false); + other_synchro = _find_matching_comm(&mbox->comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data, this_comm, + /*remove_matching*/ false); } return other_synchro; -- 2.20.1