Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / kernel / activity / SemaphoreImpl.cpp
index 61fd945..2bb6396 100644 (file)
@@ -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. */
@@ -15,9 +15,7 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_semaphore, ker_synchro, "Semaphore kernel-space implementation");
 
-namespace simgrid {
-namespace kernel {
-namespace activity {
+namespace simgrid::kernel::activity {
 
 /* -------- Acquisition -------- */
 
@@ -33,8 +31,8 @@ void SemAcquisitionImpl::wait_for(actor::ActorImpl* issuer, double timeout)
   if (granted_) {
     post();
   } 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
@@ -47,11 +45,11 @@ 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
-    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);
 
@@ -64,8 +62,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;
@@ -89,12 +87,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;
 }
@@ -119,6 +117,4 @@ void SemaphoreImpl::release()
   }
 }
 
-} // namespace activity
-} // namespace kernel
-} // namespace simgrid
+} // namespace simgrid::kernel::activity