From f4e9eed9a710cd589a2ab070348121e9c4c3a861 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 13 Mar 2021 22:25:04 +0100 Subject: [PATCH] Use Mutex::create() for sg_mutex_init(). Also make constructor private to enforce usage of create(), and fix bogus destructor. Wanted to make ~Mutex() private, but failed to make it compile :( --- include/simgrid/s4u/Mutex.hpp | 3 +-- src/s4u/s4u_Mutex.cpp | 13 ++----------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index 237479588f..f97eae8f03 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -37,14 +37,13 @@ class XBT_PUBLIC Mutex { friend XBT_PUBLIC void intrusive_ptr_add_ref(const Mutex* mutex); friend XBT_PUBLIC void intrusive_ptr_release(const Mutex* mutex); -public: explicit Mutex(kernel::activity::MutexImpl* mutex) : pimpl_(mutex) {} - ~Mutex(); #ifndef DOXYGEN Mutex(Mutex const&) = delete; // No copy constructor; Use MutexPtr instead Mutex& operator=(Mutex const&) = delete; // No direct assignment either. Use MutexPtr instead #endif +public: /** Constructs a new mutex */ static MutexPtr create(); void lock(); diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index e855283e86..3881cf2c06 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -12,12 +12,6 @@ namespace simgrid { namespace s4u { -Mutex::~Mutex() -{ - if (pimpl_ != nullptr) - pimpl_->unref(); -} - /** @brief Blocks the calling actor until the mutex can be obtained */ void Mutex::lock() { @@ -76,10 +70,7 @@ void intrusive_ptr_release(const Mutex* mutex) /* **************************** Public C interface *************************** */ sg_mutex_t sg_mutex_init() { - simgrid::kernel::activity::MutexImpl* mutex = - simgrid::kernel::actor::simcall([] { return new simgrid::kernel::activity::MutexImpl(); }); - - return new simgrid::s4u::Mutex(mutex); + return simgrid::s4u::Mutex::create().detach(); } void sg_mutex_lock(sg_mutex_t mutex) @@ -99,5 +90,5 @@ int sg_mutex_try_lock(sg_mutex_t mutex) void sg_mutex_destroy(const_sg_mutex_t mutex) { - delete mutex; + intrusive_ptr_release(mutex); } -- 2.20.1