Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have only one refcounting system for the activities
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 30 May 2017 09:04:15 +0000 (11:04 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 30 May 2017 09:04:15 +0000 (11:04 +0200)
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/ActivityImpl.hpp
src/simix/smx_network.cpp

index 08e2a63..8506c1d 100644 (file)
@@ -10,18 +10,18 @@ simgrid::kernel::activity::ActivityImpl::~ActivityImpl() = default;
 
 void simgrid::kernel::activity::ActivityImpl::ref()
 {
-  refcount++;
+  // Atomic operation! Do not split in two instructions!
+  xbt_assert(refcount_ != 0);
+  refcount_++;
 }
 
-bool simgrid::kernel::activity::ActivityImpl::unref()
+void simgrid::kernel::activity::ActivityImpl::unref()
 {
-  xbt_assert(refcount > 0,
-      "This activity has a negative refcount! You can only call test() or wait() once per activity.");
+  xbt_assert(refcount_ > 0,
+             "This activity has a negative refcount! You can only call test() or wait() once per activity.");
 
-  refcount--;
-  if (refcount>0)
-    return false;
-  delete this;
-
-  return true;
+  // Atomic operation! Do not split in two instructions!
+  auto count = --refcount_;
+  if (count == 0)
+    delete this;
 }
index 1757126..e144296 100644 (file)
@@ -34,27 +34,21 @@ namespace activity {
     // boost::intrusive_ptr<Activity> support:
     friend void intrusive_ptr_add_ref(ActivityImpl * activity)
     {
-      // Atomic operation! Do not split in two instructions!
-      XBT_ATTRIB_UNUSED auto previous = (activity->refcount_)++;
-      xbt_assert(previous != 0);
+      activity->ref();
     }
 
     friend void intrusive_ptr_release(ActivityImpl * activity)
     {
-      // Atomic operation! Do not split in two instructions!
-      auto count = --(activity->refcount_);
-      if (count == 0)
-        delete activity;
+      activity->unref();
     }
 
-    /** @brief Increase the refcount */
+    /** @brief Increases the refcount */
     void ref();
-    /** @brief Reduce the refcount; returns true if the object was destroyed */
-    bool unref();
+    /** @brief Reduces the refcount */
+    void unref();
 
   private:
     std::atomic_int_fast32_t refcount_{1};
-    int refcount = 1;
   };
 }}} // namespace simgrid::kernel::activity
 
index 410eb3b..74cdf59 100644 (file)
@@ -726,7 +726,7 @@ void SIMIX_comm_copy_data(smx_activity_t synchro)
 smx_activity_t SIMIX_comm_ref(smx_activity_t comm)
 {
   if (comm != nullptr)
-    intrusive_ptr_add_ref(comm);
+    comm->ref();
   return comm;
 }
 
@@ -734,5 +734,5 @@ smx_activity_t SIMIX_comm_ref(smx_activity_t comm)
 void SIMIX_comm_unref(smx_activity_t comm)
 {
   if (comm != nullptr)
-    intrusive_ptr_release(comm);
+    comm->unref();
 }