- if (not locked_)
- THROWF(mismatch_error, 0, "Cannot release that mutex: it was not locked.");
-
- /* If the mutex is not owned by the issuer, that's not good */
- if (issuer != owner_)
- THROWF(mismatch_error, 0, "Cannot release that mutex: it was locked by %s (pid:%ld), not by you.",
- owner_->get_cname(), owner_->get_pid());
-
- if (not sleeping_.empty()) {
- /*process to wake up */
- actor::ActorImpl* p = &sleeping_.front();
- sleeping_.pop_front();
- p->waiting_synchro = nullptr;
- owner_ = p;
- SIMIX_simcall_answer(&p->simcall);
+ xbt_assert(issuer == owner_, "Cannot release that mutex: you're not the owner. %s is (pid:%ld).",
+ owner_ != nullptr ? owner_->get_cname() : "(nobody)", owner_ != nullptr ? owner_->get_pid() : -1);
+
+ if (not ongoing_acquisitions_.empty()) {
+ /* Give the ownership to the first waiting actor */
+ auto acq = ongoing_acquisitions_.front();
+ ongoing_acquisitions_.pop_front();
+
+ owner_ = acq->get_issuer();
+ if (acq == owner_->waiting_synchro_)
+ acq->finish();
+ // else, the issuer is not blocked on this acquisition so no need to release it
+