From 63d238ad4d74226fae3321cb5c128f03160dacb2 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 13 Nov 2023 00:55:37 +0100 Subject: [PATCH] Check in the right location that a mutex is provided to cond_wait --- src/kernel/activity/ConditionVariableImpl.cpp | 18 ++++++++---------- src/kernel/activity/MutexImpl.cpp | 2 +- src/kernel/actor/SynchroObserver.hpp | 1 + 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/kernel/activity/ConditionVariableImpl.cpp b/src/kernel/activity/ConditionVariableImpl.cpp index fdc23b405b..ec3fb6ae52 100644 --- a/src/kernel/activity/ConditionVariableImpl.cpp +++ b/src/kernel/activity/ConditionVariableImpl.cpp @@ -62,16 +62,14 @@ void ConditionVariableImpl::wait(MutexImpl* mutex, double timeout, actor::ActorI XBT_DEBUG("Wait condition %p", this); xbt_assert(std::isfinite(timeout), "timeout is not finite!"); - /* If there is a mutex unlock it */ - if (mutex != nullptr) { - auto* owner = mutex->get_owner(); - xbt_assert(owner == issuer, - "Actor %s cannot wait on ConditionVariable %p since it does not own the provided mutex %p (which is " - "owned by %s).", - issuer->get_cname(), this, mutex, (owner == nullptr ? "nobody" : owner->get_cname())); - mutex_ = mutex; - mutex->unlock(issuer); - } + /* Unlock the provided mutex (the simcall observer ensures that one is provided, no need to check) */ + auto* owner = mutex->get_owner(); + xbt_assert(owner == issuer, + "Actor %s cannot wait on ConditionVariable %p since it does not own the provided mutex %p (which is " + "owned by %s).", + issuer->get_cname(), this, mutex, (owner == nullptr ? "nobody" : owner->get_cname())); + mutex_ = mutex; + mutex->unlock(issuer); SynchroImplPtr synchro(new SynchroImpl([this, issuer]() { this->remove_sleeping_actor(*issuer); diff --git a/src/kernel/activity/MutexImpl.cpp b/src/kernel/activity/MutexImpl.cpp index c981c3ee76..cac3e9524d 100644 --- a/src/kernel/activity/MutexImpl.cpp +++ b/src/kernel/activity/MutexImpl.cpp @@ -74,7 +74,7 @@ MutexAcquisitionImplPtr MutexImpl::lock_async(actor::ActorImpl* issuer) return res; } - // None-recursive mutex + // Non-recursive mutex auto res = MutexAcquisitionImplPtr(new kernel::activity::MutexAcquisitionImpl(issuer, this), true); if (owner_ == nullptr) { // Lock is free, take it owner_ = issuer; diff --git a/src/kernel/actor/SynchroObserver.hpp b/src/kernel/actor/SynchroObserver.hpp index dc10e63afe..b2bfd31fe8 100644 --- a/src/kernel/actor/SynchroObserver.hpp +++ b/src/kernel/actor/SynchroObserver.hpp @@ -92,6 +92,7 @@ public: double timeout = -1.0) : ResultingSimcall(actor, false), cond_(cond), mutex_(mutex), timeout_(timeout) { + xbt_assert(mutex != nullptr, "Cannot wait on a condition variable without a valid mutex"); } void serialize(std::stringstream& stream) const override; std::string to_string() const override; -- 2.20.1