Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the refcounting in this C example
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 4 Feb 2020 08:51:22 +0000 (09:51 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 4 Feb 2020 08:51:22 +0000 (09:51 +0100)
include/simgrid/s4u/Activity.hpp
src/s4u/s4u_Mailbox.cpp

index 75e5d98..d735b36 100644 (file)
@@ -116,6 +116,16 @@ public:
   }
   friend void intrusive_ptr_add_ref(Activity* a) { a->refcount_.fetch_add(1, std::memory_order_relaxed); }
 #endif
+  Activity* add_ref()
+  {
+    intrusive_ptr_add_ref(this);
+    return this;
+  }
+  Activity* unref()
+  {
+    intrusive_ptr_release(this);
+    return this;
+  }
 
 private:
   kernel::activity::ActivityImplPtr pimpl_ = nullptr;
index 0b565a6..1287202 100644 (file)
@@ -173,7 +173,9 @@ const char* sg_mailbox_get_name(sg_mailbox_t mailbox)
 
 sg_comm_t sg_mailbox_put_async(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
 {
-  return (mailbox->put_async(payload, simulated_size_in_bytes)).detach();
+  auto comm = mailbox->put_async(payload, simulated_size_in_bytes);
+  comm->add_ref();
+  return comm.get();
 }
 
 /** @brief Set the mailbox to receive in asynchronous mode