Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify intrusive_ptr_release to speed it up and fix a race condition
[simgrid.git] / src / kernel / activity / ActivityImpl.cpp
index c732b28..43ed70f 100644 (file)
@@ -12,31 +12,16 @@ namespace activity {
 ActivityImpl::ActivityImpl()  = default;
 ActivityImpl::~ActivityImpl() = default;
 
-void ActivityImpl::ref()
-{
-  // Atomic operation! Do not split in two instructions!
-  xbt_assert(refcount_ != 0);
-  refcount_++;
-}
-
-void ActivityImpl::unref()
-{
-  xbt_assert(refcount_ > 0,
-             "This activity has a negative refcount! You can only call test() or wait() once per activity.");
-  refcount_--;
-  if (refcount_ == 0)
-    delete this;
-}
-
 // boost::intrusive_ptr<Activity> support:
 void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
 {
-  activity->ref();
+  activity->refcount_++;
 }
 
 void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
 {
-  activity->unref();
+  if (activity->refcount_-- == 0)
+    delete activity;
 }
 }
 }