Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make pc_id a static member of ProducerConsumer.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 27 Jan 2023 16:07:29 +0000 (17:07 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Jan 2023 14:52:36 +0000 (15:52 +0100)
include/simgrid/plugins/ProducerConsumer.hpp
src/plugins/ProducerConsumer.cpp

index c45563f..1ecaa1e 100644 (file)
@@ -28,9 +28,16 @@ namespace plugin {
 template <typename T> class ProducerConsumer;
 template <typename T> using ProducerConsumerPtr = boost::intrusive_ptr<ProducerConsumer<T>>;
 
-XBT_PUBLIC_DATA unsigned long pc_id;
+class ProducerConsumerId {
+private:
+  static unsigned long pc_id;
+
+protected:
+  const std::string id = "ProducerConsumer" + std::to_string(pc_id);
+  ProducerConsumerId() { ++pc_id; }
+};
 
-template <typename T> class ProducerConsumer {
+template <typename T> class ProducerConsumer : public ProducerConsumerId {
 public:
   /** This ProducerConsumer plugin can use two different transfer modes:
    *   - TransferMode::MAILBOX: this mode induces a s4u::Comm between the actors doing the calls to put() and get().
@@ -45,8 +52,6 @@ public:
   enum class TransferMode { MAILBOX = 0, QUEUE };
 
 private:
-  std::string id;
-
   /* Implementation of a Monitor to handle the data exchanges */
   s4u::MutexPtr mutex_;
   s4u::ConditionVariablePtr can_put_;
@@ -75,9 +80,6 @@ private:
   {
     xbt_assert(max_queue_size > 0, "Max queue size of 0 is not allowed");
 
-    id = "ProducerConsumer" + std::to_string(pc_id);
-    pc_id++;
-
     mutex_   = s4u::Mutex::create();
     can_put_ = s4u::ConditionVariable::create();
     can_get_ = s4u::ConditionVariable::create();
index d521522..2614a1b 100644 (file)
@@ -8,5 +8,5 @@
 XBT_LOG_NEW_CATEGORY(producer_consumer, "Producer-Consumer plugin logging category");
 
 namespace simgrid::plugin {
-unsigned long pc_id = 0;
+unsigned long ProducerConsumerId::pc_id = 0;
 }