From: Frederic Suter Date: Sat, 23 Feb 2019 11:27:27 +0000 (+0100) Subject: SIMIX_mutex_{un}ref become MutexImpl::{un}ref X-Git-Tag: v3_22~256 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/32db5a3c200f56f6c965eeddc14e6f88341acbe8 SIMIX_mutex_{un}ref become MutexImpl::{un}ref --- diff --git a/src/kernel/activity/MutexImpl.cpp b/src/kernel/activity/MutexImpl.cpp index 80fa3d529d..40f60bbc6b 100644 --- a/src/kernel/activity/MutexImpl.cpp +++ b/src/kernel/activity/MutexImpl.cpp @@ -96,9 +96,22 @@ void MutexImpl::unlock(smx_actor_t issuer) } XBT_OUT(); } +/** Increase the refcount for this mutex */ +MutexImpl* MutexImpl::ref() +{ + intrusive_ptr_add_ref(this); + return this; } + +/** Decrease the refcount for this mutex */ +void MutexImpl::unref() +{ + intrusive_ptr_release(this); } -} + +} // namespace activity +} // namespace kernel +} // namespace simgrid /** Increase the refcount for this mutex */ smx_mutex_t SIMIX_mutex_ref(smx_mutex_t mutex) diff --git a/src/kernel/activity/MutexImpl.hpp b/src/kernel/activity/MutexImpl.hpp index 613d799477..52256b0878 100644 --- a/src/kernel/activity/MutexImpl.hpp +++ b/src/kernel/activity/MutexImpl.hpp @@ -25,6 +25,8 @@ public: bool try_lock(smx_actor_t issuer); void unlock(smx_actor_t issuer); + MutexImpl* ref(); + void unref(); bool locked = false; smx_actor_t owner = nullptr; // List of sleeping processes: diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index 88a271b0e5..5e0b6a7943 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -11,8 +11,10 @@ namespace s4u { Mutex::~Mutex() { - SIMIX_mutex_unref(pimpl_); + if (pimpl_ != nullptr) + pimpl_->unref(); } + /** @brief Blocks the calling actor until the mutex can be obtained */ void Mutex::lock() { @@ -48,12 +50,15 @@ MutexPtr Mutex::create() void intrusive_ptr_add_ref(Mutex* mutex) { xbt_assert(mutex); - SIMIX_mutex_ref(mutex->pimpl_); + if (mutex->pimpl_) + mutex->pimpl_->ref(); } void intrusive_ptr_release(Mutex* mutex) { xbt_assert(mutex); - SIMIX_mutex_unref(mutex->pimpl_); + if (mutex->pimpl_) + mutex->pimpl_->unref(); } + } // namespace s4u } // namespace simgrid