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;
}
// 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
smx_activity_t SIMIX_comm_ref(smx_activity_t comm)
{
if (comm != nullptr)
- intrusive_ptr_add_ref(comm);
+ comm->ref();
return comm;
}
void SIMIX_comm_unref(smx_activity_t comm)
{
if (comm != nullptr)
- intrusive_ptr_release(comm);
+ comm->unref();
}