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

Public GIT Repository
obey our coding conventions in ActorImpl::mailboxes, and free them once only
[simgrid.git] / src / kernel / activity / SemaphoreImpl.cpp
index 9e340d71061bc4fdb082e6f540c34b1dfbaa4f1a..914ef4ca713088b57a0e2871d621c9824ceac920 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "src/kernel/activity/SemaphoreImpl.hpp"
 #include "src/kernel/activity/Synchro.hpp"
-#include "src/kernel/actor/SimcallObserver.hpp"
+#include "src/kernel/actor/SynchroObserver.hpp"
 #include "src/kernel/resource/CpuImpl.hpp"
 
 #include <cmath> // std::isfinite
@@ -19,6 +19,8 @@ namespace simgrid {
 namespace kernel {
 namespace activity {
 
+/* -------- Acquisition -------- */
+
 void SemAcquisitionImpl::wait_for(actor::ActorImpl* issuer, double timeout)
 {
   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
@@ -45,7 +47,7 @@ void SemAcquisitionImpl::post()
 void SemAcquisitionImpl::finish()
 {
   xbt_assert(simcalls_.size() == 1, "Unexpected number of simcalls waiting: %zu", simcalls_.size());
-  smx_simcall_t simcall = simcalls_.front();
+  actor::Simcall* simcall = simcalls_.front();
   simcalls_.pop_front();
 
   if (surf_action_ != nullptr) { // A timeout was declared
@@ -54,16 +56,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_->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);
+        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::SemaphoreAcquisitionObserver*>(get_issuer()->simcall_.observer_);
         xbt_assert(observer != nullptr);
         observer->set_result(true);
       }
@@ -75,6 +71,19 @@ 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);
+}
+
+/* -------- Semaphore -------- */
+unsigned SemaphoreImpl::next_id_ = 0;
 
 SemAcquisitionImplPtr SemaphoreImpl::acquire_async(actor::ActorImpl* issuer)
 {