Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Check in the right location that a mutex is provided to cond_wait
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 12 Nov 2023 23:55:37 +0000 (00:55 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 13 Nov 2023 15:05:52 +0000 (16:05 +0100)
src/kernel/activity/ConditionVariableImpl.cpp
src/kernel/activity/MutexImpl.cpp
src/kernel/actor/SynchroObserver.hpp

index fdc23b4..ec3fb6a 100644 (file)
@@ -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);
index c981c3e..cac3e95 100644 (file)
@@ -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;
index dc10e63..b2bfd31 100644 (file)
@@ -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;