Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define Mailbox::get_unique() returning a std::unique_ptr.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 12:38:36 +0000 (13:38 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 13:17:38 +0000 (14:17 +0100)
ChangeLog
examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.cpp
examples/s4u/trace-process-migration/s4u-trace-process-migration.cpp
include/simgrid/s4u/Mailbox.hpp

index 1a5c603..6b37281 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@ User-visible changes:
    - 'clean-atexit' is now 'debug/clean-atexit'
 
 S4U:
+- Define new template functions Mailbox::get_unique(), returning a std::unique_ptr.
 - Functions Mailbox::get() and Mailbox::get_async() are now templated with the
   type of the pointee. Untyped functions are deprecated. Use Mailbox::get<void>()
   or Mailbox::get_async<void>() if you really want to play with void*.
@@ -69,9 +70,9 @@ SMPI:
  - smpicc/cxx/ff/f90 now will actually perform definition checks at link time. When
    building shared libraries, this may cause issues, so environment variable
    SMPI_NO_UNDEFINED_CHECK can be added to disable this.
- - most temporary files should now be created in /tmp dir (or equivalent). 
+ - most temporary files should now be created in /tmp dir (or equivalent).
    If this one does not allow execution of code (noexec flag), this may cause issues.
-   Please use another tmp directory (using TMPDIR or equivalent system variable) 
+   Please use another tmp directory (using TMPDIR or equivalent system variable)
    in this case.
 
 Model-Checker:
index 8600357..0926593 100644 (file)
@@ -29,7 +29,7 @@ static void sender(std::string mailbox, double msg_size, unsigned sleep_time)
 static void receiver(std::string mailbox)
 {
   auto* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
-  auto msg   = std::unique_ptr<Message>(mbox->get<Message>());
+  auto msg   = mbox->get_unique<Message>();
   XBT_INFO("[%s] %s received %d bytes from %s",
            mailbox.c_str(),
            simgrid::s4u::this_actor::get_host()->get_name().c_str(),
index 7e77660..4b02c75 100644 (file)
@@ -20,7 +20,7 @@ static void emigrant()
   simgrid::s4u::this_actor::sleep_for(2);
 
   while (true) { // I am an eternal emigrant
-    auto destination = std::unique_ptr<std::string>(mailbox->get<std::string>());
+    auto destination = mailbox->get_unique<std::string>();
     if (destination->empty())
       break; // there is no destination, die
     simgrid::s4u::this_actor::set_host(simgrid::s4u::Host::by_name(*destination));
index 07e7e03..4f07472 100644 (file)
@@ -11,6 +11,7 @@
 #include <smpi/forward.hpp>
 #include <xbt/string.hpp>
 
+#include <memory>
 #include <string>
 
 namespace simgrid {
@@ -100,9 +101,12 @@ public:
   /** Blocking data reception */
   template <typename T> T* get() { return static_cast<T*>(get<void>()); }
   XBT_ATTRIB_DEPRECATED_v331("Please use typed template Mailbox::get<>()") void* get();
+  template <typename T> std::unique_ptr<T> get_unique() { return std::unique_ptr<T>(get<T>()); }
+
   /** Blocking data reception with timeout */
   template <typename T> T* get(double timeout) { return static_cast<T*>(get<void>(timeout)); }
   XBT_ATTRIB_DEPRECATED_v331("Please use typed template Mailbox::get<>()") void* get(double timeout);
+  template <typename T> std::unique_ptr<T> get_unique(double timeout) { return std::unique_ptr<T>(get<T>(timeout)); }
 };
 
 template <> CommPtr Mailbox::get_async<void>(void** data);