X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d1ce25d36729721b7d7eed0fa4425e401db8a092..b22d0e4d776668a22f7bc6a680cc999c17fd43d4:/src/kernel/activity/ActivityImpl.cpp diff --git a/src/kernel/activity/ActivityImpl.cpp b/src/kernel/activity/ActivityImpl.cpp index c732b28eea..0a6880363e 100644 --- a/src/kernel/activity/ActivityImpl.cpp +++ b/src/kernel/activity/ActivityImpl.cpp @@ -12,31 +12,18 @@ 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 support: void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity) { - activity->ref(); + activity->refcount_.fetch_add(1, std::memory_order_relaxed); } void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity) { - activity->unref(); + if (activity->refcount_.fetch_sub(1, std::memory_order_release) == 1) { + std::atomic_thread_fence(std::memory_order_acquire); + delete activity; + } } } }