X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/72d32c4e88a57f4786f62fec48a1bfa454adbff9..3c7c64745aa5e60415bb85af482c7b0d0fca2b2b:/src/kernel/activity/SemaphoreImpl.cpp diff --git a/src/kernel/activity/SemaphoreImpl.cpp b/src/kernel/activity/SemaphoreImpl.cpp index c53825f872..b53f45771b 100644 --- a/src/kernel/activity/SemaphoreImpl.cpp +++ b/src/kernel/activity/SemaphoreImpl.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -29,27 +29,23 @@ void SemAcquisitionImpl::wait_for(actor::ActorImpl* issuer, double timeout) this->register_simcall(&issuer_->simcall_); // Block on that acquisition if (granted_) { - post(); + finish(); } else if (timeout > 0) { - surf_action_ = get_issuer()->get_host()->get_cpu()->sleep(timeout); - surf_action_->set_activity(this); + model_action_ = get_issuer()->get_host()->get_cpu()->sleep(timeout); + model_action_->set_activity(this); } else { // Already in the queue } } -void SemAcquisitionImpl::post() -{ - finish(); -} void SemAcquisitionImpl::finish() { xbt_assert(simcalls_.size() == 1, "Unexpected number of simcalls waiting: %zu", simcalls_.size()); actor::Simcall* simcall = simcalls_.front(); simcalls_.pop_front(); - if (surf_action_ != nullptr) { // A timeout was declared - if (surf_action_->get_state() == resource::Action::State::FINISHED) { // The timeout elapsed + if (model_action_ != nullptr) { // A timeout was declared + if (model_action_->get_state() == resource::Action::State::FINISHED) { // The timeout elapsed if (granted_) { // but we got the semaphore, just in time! set_state(State::DONE); @@ -62,8 +58,8 @@ void SemAcquisitionImpl::finish() observer->set_result(true); } } - surf_action_->unref(); - surf_action_ = nullptr; + model_action_->unref(); + model_action_ = nullptr; } simcall->issuer_->waiting_synchro_ = nullptr; @@ -72,7 +68,7 @@ void SemAcquisitionImpl::finish() void SemAcquisitionImpl::cancel() { /* Remove myself from the list of interested parties */ - auto issuer = get_issuer(); + const auto* issuer = get_issuer(); auto it = std::find_if(semaphore_->ongoing_acquisitions_.begin(), semaphore_->ongoing_acquisitions_.end(), [issuer](SemAcquisitionImplPtr acqui) { return acqui->get_issuer() == issuer; }); xbt_assert(it != semaphore_->ongoing_acquisitions_.end(), @@ -87,12 +83,12 @@ SemAcquisitionImplPtr SemaphoreImpl::acquire_async(actor::ActorImpl* issuer) { auto res = SemAcquisitionImplPtr(new kernel::activity::SemAcquisitionImpl(issuer, this), true); - if (value_ <= 0) { - /* No free token in the semaphore; register the acquisition */ - ongoing_acquisitions_.push_back(res); - } else { + if (value_ > 0) { value_--; res->granted_ = true; + } else { + /* No free token in the semaphore; register the acquisition */ + ongoing_acquisitions_.push_back(res); } return res; } @@ -108,7 +104,7 @@ void SemaphoreImpl::release() acqui->granted_ = true; if (acqui == acqui->get_issuer()->waiting_synchro_) - acqui->post(); + acqui->finish(); // else, the issuer is not blocked on this acquisition so no need to release it } else {