From 35bf365de6be434aeeafa8b3d5f5c9a1e3082ce3 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 13 Nov 2023 01:10:41 +0100 Subject: [PATCH] Sanity check that mutex are empty when destroyed --- src/kernel/activity/MutexImpl.hpp | 8 ++++++-- src/s4u/s4u_Mutex.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/kernel/activity/MutexImpl.hpp b/src/kernel/activity/MutexImpl.hpp index 9d9242b4a5..cad25c34c9 100644 --- a/src/kernel/activity/MutexImpl.hpp +++ b/src/kernel/activity/MutexImpl.hpp @@ -9,6 +9,7 @@ #include "simgrid/s4u/Mutex.hpp" #include "src/kernel/activity/ActivityImpl.hpp" #include "src/kernel/actor/ActorImpl.hpp" +#include "xbt/asserts.h" #include namespace simgrid::kernel::activity { @@ -96,11 +97,14 @@ public: friend void intrusive_ptr_release(MutexImpl* mutex) { - if (mutex->refcount_.fetch_sub(1) == 1) + if (mutex->refcount_.fetch_sub(1) == 1) { + xbt_assert(mutex->ongoing_acquisitions_.empty(), "The destroyed mutex still had ongoing acquisitions"); + xbt_assert(mutex->owner_ == nullptr, "The destroyed mutex is still owned by %s", mutex->owner_->get_cname()); delete mutex; + } } - s4u::Mutex& mutex() { return piface_; } + s4u::Mutex& get_iface() { return piface_; } }; } // namespace simgrid::kernel::activity #endif diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index e2cc10d007..72c2481736 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -58,7 +58,7 @@ bool Mutex::try_lock() MutexPtr Mutex::create(bool recursive) { auto* mutex = new kernel::activity::MutexImpl(recursive); - return MutexPtr(&mutex->mutex(), false); + return MutexPtr(&mutex->get_iface(), false); } Actor* Mutex::get_owner() -- 2.20.1