Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Lookup only once on mailbox creation.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 14:58:42 +0000 (16:58 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 14:59:28 +0000 (16:59 +0200)
src/s4u/s4u_Engine.cpp

index f664690..6cdb275 100644 (file)
@@ -247,14 +247,13 @@ Mailbox* Engine::mailbox_by_name_or_create(const std::string& name) const
 {
   /* two actors may have pushed the same mbox_create simcall at the same time */
   kernel::activity::MailboxImpl* mbox = kernel::actor::simcall([&name, this] {
-    auto m = pimpl->mailboxes_.find(name);
-    if (m == pimpl->mailboxes_.end()) {
+    auto m = pimpl->mailboxes_.emplace(name, nullptr);
+    if (m.second) {
       auto* mbox = new kernel::activity::MailboxImpl(name);
       XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name.c_str());
-      pimpl->mailboxes_[name] = mbox;
-      return mbox;
-    } else
-      return m->second;
+      m.first->second = mbox;
+    }
+    return m.first->second;
   });
   return mbox->get_iface();
 }