Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MailboxImpl: snake_case and follow our coding standards
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 13 Jul 2018 20:07:15 +0000 (22:07 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 13 Jul 2018 20:13:13 +0000 (22:13 +0200)
src/kernel/activity/MailboxImpl.cpp
src/kernel/activity/MailboxImpl.hpp
src/s4u/s4u_Mailbox.cpp
src/simix/smx_network.cpp

index ebf615e..f519fa2 100644 (file)
@@ -25,7 +25,7 @@ namespace simgrid {
 namespace kernel {
 namespace activity {
 /** @brief Returns the mailbox of that name, or nullptr */
 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())
 {
   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 */
     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);
 {
   /* 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
  */
 /** @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)
 {
   if (actor != nullptr)
-    this->permanent_receiver = actor.get()->get_impl();
+    this->permanent_receiver_ = actor->get_impl();
   else
   else
-    this->permanent_receiver = nullptr;
+    this->permanent_receiver_ = nullptr;
 }
 /** @brief Pushes a communication activity into a mailbox
  *  @param comm What to add
 }
 /** @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;
 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
 }
 
 /** @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;
   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) {
     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());
       return;
     }
   xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname());
index b965ea5..f7a3357 100644 (file)
@@ -21,25 +21,31 @@ namespace activity {
 /** @brief Implementation of the simgrid::s4u::Mailbox */
 
 class MailboxImpl {
 /** @brief Implementation of the simgrid::s4u::Mailbox */
 
 class MailboxImpl {
+  friend s4u::Mailbox;
+
   explicit MailboxImpl(std::string name)
   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(); }
   {
   }
 
 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);
   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::xbt::string name_;
 
-  simgrid::kernel::actor::ActorImplPtr permanent_receiver; // actor to which the mailbox is attached
-  boost::circular_buffer_space_optimized<smx_activity_t> comm_queue;
-  boost::circular_buffer_space_optimized<smx_activity_t> 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<smx_activity_t> comm_queue_;
+  boost::circular_buffer_space_optimized<smx_activity_t>
+      done_comm_queue_; // messages already received in the permanent receive mode
 };
 }
 }
 };
 }
 }
index 03c12aa..a810de4 100644 (file)
@@ -26,39 +26,39 @@ const char* Mailbox::get_cname() const
 
 MailboxPtr Mailbox::by_name(std::string name)
 {
 
 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) {
   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 MailboxPtr(&mbox->piface_, true);
 }
 
 bool Mailbox::empty()
 {
-  return pimpl_->comm_queue.empty();
+  return pimpl_->comm_queue_.empty();
 }
 
 bool Mailbox::listen()
 {
 }
 
 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()
 {
 }
 
 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)
 {
 }
 
 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()
 {
 }
 
 /** @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 ActorPtr();
-  return pimpl_->permanent_receiver->iface();
+  return pimpl_->permanent_receiver_->iface();
 }
 
 CommPtr Mailbox::put_init()
 }
 
 CommPtr Mailbox::put_init()
index 8e1cfdb..da781c8 100644 (file)
@@ -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 =
    *
    * 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 (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;
       //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{
       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
 
   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
 
     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) {
                                      /*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 */
      * 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) {
                                      /*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 {
       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)
 {
 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){
   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;
     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");
     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");
   }
   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;
   }
 
   return other_synchro;