From 4fb5244980199691e9976323c2c3a09ebb168242 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 12 Nov 2023 23:30:43 +0100 Subject: [PATCH] New function s4u::Mutex::get_owner() --- ChangeLog | 1 + include/simgrid/s4u/Mutex.hpp | 3 +++ src/s4u/s4u_Mutex.cpp | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/ChangeLog b/ChangeLog index 66d4a379a9..c8084cea5d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ S4U: The behavior of a MessageQueue is similar to that of a Mailbox, but intended for control messages that do not incur any simulated cost. Information is automagically transported over thin air between producer and consumer. See examples/cpp/mess-wait + - New function: Mutex::get_owner() New S4U plugins: - Add a JBOD (just a bunch of disks) concept. It's a sort of host with many disks. diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index 06f04c2aa5..29d9ed1043 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -6,6 +6,7 @@ #ifndef SIMGRID_S4U_MUTEX_HPP #define SIMGRID_S4U_MUTEX_HPP +#include "simgrid/s4u/Actor.hpp" #include #include @@ -55,6 +56,8 @@ public: void lock(); void unlock(); bool try_lock(); + + Actor* get_owner(); }; } // namespace simgrid::s4u diff --git a/src/s4u/s4u_Mutex.cpp b/src/s4u/s4u_Mutex.cpp index 12fa915d5b..e2cc10d007 100644 --- a/src/s4u/s4u_Mutex.cpp +++ b/src/s4u/s4u_Mutex.cpp @@ -61,6 +61,14 @@ MutexPtr Mutex::create(bool recursive) return MutexPtr(&mutex->mutex(), false); } +Actor* Mutex::get_owner() +{ + auto* owner = pimpl_->get_owner(); + if (owner == nullptr) + return nullptr; + return owner->get_ciface(); +} + /* refcounting of the intrusive_ptr is delegated to the implementation object */ void intrusive_ptr_add_ref(const Mutex* mutex) { -- 2.20.1