Skip to content
Snippets Groups Projects
mochi-thallium.patch 2.89 KiB
Newer Older
diff --git a/include/thallium/packed_data.hpp b/include/thallium/packed_data.hpp
index 9e6e76e..37e64d3 100644
--- a/include/thallium/packed_data.hpp
+++ b/include/thallium/packed_data.hpp
@@ -14,13 +14,13 @@

 namespace thallium {

-template<typename ... CtxArg> class callable_remote_procedure_with_context;
+template <typename... CtxArg> class callable_remote_procedure_with_context;
 class async_response;
-template<typename ... CtxArg> class request_with_context;
+template <typename... CtxArg> class request_with_context;
 using request = request_with_context<>;

 namespace detail {
-    struct engine_impl;
+struct engine_impl;
 }

 /**
@@ -36,9 +36,9 @@ class packed_data {

   private:
     std::weak_ptr<detail::engine_impl> m_engine_impl;
-    hg_handle_t m_handle = HG_HANDLE_NULL;
-    hg_return_t (*m_unpack_fn)(hg_handle_t,void*) = nullptr;
-    hg_return_t (*m_free_fn)(hg_handle_t,void*) = nullptr;
+    hg_handle_t                        m_handle    = HG_HANDLE_NULL;
+    hg_return_t (*m_unpack_fn)(hg_handle_t, void*) = nullptr;
+    hg_return_t (*m_free_fn)(hg_handle_t, void*)   = nullptr;
     mutable std::tuple<CtxArg...> m_context;

     /**
@@ -62,6 +62,41 @@ class packed_data {
         MARGO_ASSERT(ret, margo_ref_incr);
     }

+    packed_data(const packed_data&)            = delete;
+    packed_data& operator=(const packed_data&) = delete;
+
+    packed_data(packed_data&& rhs)
+    : m_engine_impl(std::move(rhs.m_engine_impl),
+                    m_context(std::move(rhs.m_context))) {
+        m_handle        = rhs.m_handle;
+        rhs.m_handle    = HG_HANDLE_NULL;
+        m_unpack_fn     = rhs.m_unpack_fn;
+        rhs.m_unpack_fn = nullptr;
+        m_free_fn       = rhs.m_free_fn;
+        rhs.m_free_fn   = nullptr;
+    }
+
+    packed_data& operator=(packed_data&& rhs) {
+
+        if(&rhs == this) {
+            return *this;
+        }
+
+        // the original members m_handle, m_context, and m_handle are being
+        // replaced here by the ones from rhs. It may be necessary to release
+        // their resources if `packed_data` has claimed ownership over them,
+        // otherwise we would be leaking
+        m_engine_impl = std::move(rhs.m_engine_impl);
+        m_context = std::move(rhs.m_context);
+
+        m_handle        = rhs.m_handle;
+        rhs.m_handle    = HG_HANDLE_NULL;
+        m_unpack_fn     = rhs.m_unpack_fn;
+        rhs.m_unpack_fn = nullptr;
+        m_free_fn       = rhs.m_free_fn;
+        rhs.m_free_fn   = nullptr;
+    }
+
     packed_data() = default;

   public:
@@ -78,7 +113,7 @@ class packed_data {
      * @tparam NewCtxArg Types of the serialization context.
      * @param args Context.
      */
-    template<typename ... NewCtxArg>
+    template <typename... NewCtxArg>
     auto with_serialization_context(NewCtxArg&&... args) {
         return packed_data<unwrap_decay_t<NewCtxArg>...>(
             m_unpack_fn, m_free_fn, m_handle, m_engine_impl,