]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/activity/SemaphoreImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Const methods.
[simgrid.git] / src / kernel / activity / SemaphoreImpl.cpp
index f707757a2f8761ec37885310900578f83bafea33..03998f275ba45daf1b7ee18227663cee808d38d6 100644 (file)
@@ -54,15 +54,10 @@ void SemAcquisitionImpl::finish()
         set_state(State::DONE);
 
       } else { // we have to report that timeout
-        /* Remove myself from the list of interested parties */
-        auto issuer = get_issuer();
-        auto it     = std::find_if(semaphore_->sleeping_.begin(), semaphore_->sleeping_.end(),
-                                   [issuer](SemAcquisitionImplPtr acqui) { return acqui->get_issuer() == issuer; });
-        xbt_assert(it != semaphore_->sleeping_.end(), "Cannot find myself in the waiting queue that I have to leave");
-        semaphore_->sleeping_.erase(it);
+        cancel(); // Unregister the acquisition from the semaphore
 
         /* Return to the englobing simcall that the wait_for timeouted */
-        auto* observer = dynamic_cast<kernel::actor::SemAcquireSimcall*>(issuer->simcall_.observer_);
+        auto* observer = dynamic_cast<kernel::actor::SemAcquireSimcall*>(get_issuer()->simcall_.observer_);
         xbt_assert(observer != nullptr);
         observer->set_result(true);
       }
@@ -74,14 +69,23 @@ void SemAcquisitionImpl::finish()
   simcall->issuer_->waiting_synchro_ = nullptr;
   simcall->issuer_->simcall_answer();
 }
-
+void SemAcquisitionImpl::cancel()
+{
+  /* Remove myself from the list of interested parties */
+  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(),
+             "Cannot find myself in the waiting queue that I have to leave");
+  semaphore_->ongoing_acquisitions_.erase(it);
+}
 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 */
-    sleeping_.push_back(res);
+    ongoing_acquisitions_.push_back(res);
   } else {
     value_--;
     res->granted_ = true;
@@ -92,11 +96,11 @@ void SemaphoreImpl::release()
 {
   XBT_DEBUG("Sem release semaphore %p", this);
 
-  if (not sleeping_.empty()) {
+  if (not ongoing_acquisitions_.empty()) {
     /* Release the first waiting actor */
 
-    auto acqui = sleeping_.front();
-    sleeping_.pop_front();
+    auto acqui = ongoing_acquisitions_.front();
+    ongoing_acquisitions_.pop_front();
 
     acqui->granted_ = true;
     if (acqui == acqui->get_issuer()->waiting_synchro_)