Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_mutex_{un}ref become MutexImpl::{un}ref
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 23 Feb 2019 11:27:27 +0000 (12:27 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sat, 23 Feb 2019 11:27:27 +0000 (12:27 +0100)
src/kernel/activity/MutexImpl.cpp
src/kernel/activity/MutexImpl.hpp
src/s4u/s4u_Mutex.cpp

index 80fa3d5..40f60bb 100644 (file)
@@ -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)
index 613d799..52256b0 100644 (file)
@@ -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:
index 88a271b..5e0b6a7 100644 (file)
@@ -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