Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't build useless temporary object (sonar, c++17).
[simgrid.git] / src / kernel / activity / SemaphoreImpl.hpp
index 9347ea9..b817599 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "simgrid/s4u/Semaphore.hpp"
 #include "src/kernel/actor/ActorImpl.hpp"
+#include "src/kernel/actor/SynchroObserver.hpp"
 
 namespace simgrid {
 namespace kernel {
@@ -27,6 +28,7 @@ class XBT_PUBLIC SemAcquisitionImpl : public ActivityImpl_T<SemAcquisitionImpl>
   bool granted_             = false;
 
   friend SemaphoreImpl;
+  friend actor::SemaphoreAcquisitionObserver;
 
 public:
   SemAcquisitionImpl(actor::ActorImpl* issuer, SemaphoreImpl* sem) : issuer_(issuer), semaphore_(sem) {}
@@ -37,6 +39,7 @@ public:
   void wait_for(actor::ActorImpl* issuer, double timeout) override;
   void post() override;
   void finish() override;
+  void cancel() override;
   void set_exception(actor::ActorImpl* issuer) override
   { /* nothing to do */
   }
@@ -46,9 +49,13 @@ 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_;
+
+  static unsigned next_id_;
+  unsigned id_ = next_id_++;
 
   friend SemAcquisitionImpl;
+  friend actor::SemaphoreObserver;
 
 public:
   explicit SemaphoreImpl(unsigned int value) : piface_(this), value_(value){};
@@ -61,7 +68,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)
   {
@@ -75,7 +82,7 @@ public:
       delete sem;
     }
   }
-
+  unsigned get_id() const { return id_; }
   s4u::Semaphore& sem() { return piface_; }
 };
 } // namespace activity