Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics: rename a variable and please sonar a tiny bit
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 25 Feb 2022 14:02:09 +0000 (15:02 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 25 Feb 2022 14:02:09 +0000 (15:02 +0100)
src/kernel/activity/MutexImpl.cpp
src/kernel/activity/MutexImpl.hpp
src/kernel/activity/SemaphoreImpl.cpp
src/kernel/activity/SemaphoreImpl.hpp

index 74af186..2ad6bde 100644 (file)
@@ -58,7 +58,7 @@ MutexAcquisitionImplPtr MutexImpl::lock_async(actor::ActorImpl* issuer)
 
   if (owner_ != nullptr) {
     /* Somebody is using the mutex; register the acquisition */
-    sleeping_.push_back(res);
+    ongoing_acquisitions_.push_back(res);
   } else {
     owner_  = issuer;
   }
@@ -96,10 +96,10 @@ void MutexImpl::unlock(actor::ActorImpl* issuer)
   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 sleeping_.empty()) {
+  if (not ongoing_acquisitions_.empty()) {
     /* Give the ownership to the first waiting actor */
-    auto acq = sleeping_.front();
-    sleeping_.pop_front();
+    auto acq = ongoing_acquisitions_.front();
+    ongoing_acquisitions_.pop_front();
 
     owner_ = acq->get_issuer();
     if (acq == owner_->waiting_synchro_)
index 1c23357..6e1075e 100644 (file)
@@ -65,15 +65,14 @@ class XBT_PUBLIC MutexImpl {
   std::atomic_int_fast32_t refcount_{1};
   s4u::Mutex piface_;
   actor::ActorImpl* owner_ = nullptr;
-  // List of sleeping actors:
-  std::deque<MutexAcquisitionImplPtr> sleeping_;
+  std::deque<MutexAcquisitionImplPtr> ongoing_acquisitions_;
   static unsigned next_id_;
-  unsigned id_;
+  unsigned id_ = next_id_++;
 
   friend MutexAcquisitionImpl;
 
 public:
-  MutexImpl() : piface_(this), id_(next_id_++) {}
+  MutexImpl() : piface_(this) {}
   MutexImpl(MutexImpl const&) = delete;
   MutexImpl& operator=(MutexImpl const&) = delete;
 
index f707757..9e340d7 100644 (file)
@@ -56,10 +56,11 @@ void SemAcquisitionImpl::finish()
       } 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(),
+        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_->sleeping_.end(), "Cannot find myself in the waiting queue that I have to leave");
-        semaphore_->sleeping_.erase(it);
+        xbt_assert(it != semaphore_->ongoing_acquisitions_.end(),
+                   "Cannot find myself in the waiting queue that I have to leave");
+        semaphore_->ongoing_acquisitions_.erase(it);
 
         /* Return to the englobing simcall that the wait_for timeouted */
         auto* observer = dynamic_cast<kernel::actor::SemAcquireSimcall*>(issuer->simcall_.observer_);
@@ -81,7 +82,7 @@ SemAcquisitionImplPtr SemaphoreImpl::acquire_async(actor::ActorImpl* issuer)
 
   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 +93,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_)
index 9347ea9..8d25263 100644 (file)
@@ -46,7 +46,7 @@ class XBT_PUBLIC SemaphoreImpl {
   std::atomic_int_fast32_t refcount_{1};
   s4u::Semaphore piface_;
   unsigned int value_;
-  std::deque<SemAcquisitionImplPtr> sleeping_; /* ongoing acquisitions */
+  std::deque<SemAcquisitionImplPtr> ongoing_acquisitions_;
 
   friend SemAcquisitionImpl;
 
@@ -61,7 +61,7 @@ public:
   bool would_block() const { return (value_ == 0); }
 
   unsigned int get_capacity() const { return value_; }
-  bool is_used() const { return not sleeping_.empty(); }
+  bool is_used() const { return not ongoing_acquisitions_.empty(); }
 
   friend void intrusive_ptr_add_ref(SemaphoreImpl* sem)
   {