Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use CRTP to factor refcounting across activity types
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Oct 2019 10:16:28 +0000 (12:16 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 10 Oct 2019 10:16:28 +0000 (12:16 +0200)
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Io.hpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp

index db486e9..5f3999f 100644 (file)
@@ -7,6 +7,7 @@
 #define SIMGRID_S4U_ACTIVITY_HPP
 
 #include "xbt/asserts.h"
 #define SIMGRID_S4U_ACTIVITY_HPP
 
 #include "xbt/asserts.h"
+#include <atomic>
 #include <simgrid/forward.h>
 #include <xbt/signal.hpp>
 
 #include <simgrid/forward.h>
 #include <xbt/signal.hpp>
 
@@ -99,8 +100,19 @@ private:
   std::string name_             = "";
   std::string tracing_category_ = "";
   void* user_data_              = nullptr;
   std::string name_             = "";
   std::string tracing_category_ = "";
   void* user_data_              = nullptr;
+  std::atomic_int_fast32_t refcount_{0};
 
 public:
 
 public:
+#ifndef DOXYGEN
+  friend XBT_PUBLIC void intrusive_ptr_release(AnyActivity* a)
+  {
+    if (a->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+      std::atomic_thread_fence(std::memory_order_acquire);
+      delete a;
+    }
+  }
+  friend XBT_PUBLIC void intrusive_ptr_add_ref(AnyActivity* a) { a->refcount_.fetch_add(1, std::memory_order_relaxed); }
+#endif
   AnyActivity* set_name(const std::string& name)
   {
     xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");
   AnyActivity* set_name(const std::string& name)
   {
     xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");
index 612266e..153be7e 100644 (file)
@@ -9,7 +9,6 @@
 #include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
 
 #include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
 
-#include <atomic>
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
 
@@ -29,7 +28,6 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
   void* src_buff_                     = nullptr;
   size_t src_buff_size_               = sizeof(void*);
   std::string tracing_category_       = "";
   void* src_buff_                     = nullptr;
   size_t src_buff_size_               = sizeof(void*);
   std::string tracing_category_       = "";
-  std::atomic_int_fast32_t refcount_{0};
   /* FIXME: expose these elements in the API */
   bool detached_                                                          = false;
   int (*match_fun_)(void*, void*, kernel::activity::CommImpl*)            = nullptr;
   /* FIXME: expose these elements in the API */
   bool detached_                                                          = false;
   int (*match_fun_)(void*, void*, kernel::activity::CommImpl*)            = nullptr;
@@ -40,8 +38,6 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
 
 public:
 #ifndef DOXYGEN
 
 public:
 #ifndef DOXYGEN
-  friend XBT_PUBLIC void intrusive_ptr_release(Comm* c);
-  friend XBT_PUBLIC void intrusive_ptr_add_ref(Comm* c);
   friend Mailbox; // Factory of comms
 #endif
 
   friend Mailbox; // Factory of comms
 #endif
 
index e55b407..3611c54 100644 (file)
@@ -11,8 +11,6 @@
 #include <simgrid/s4u/Actor.hpp>
 #include <xbt/ex.h>
 
 #include <simgrid/s4u/Actor.hpp>
 #include <xbt/ex.h>
 
-#include <atomic>
-
 namespace simgrid {
 namespace s4u {
 
 namespace simgrid {
 namespace s4u {
 
@@ -25,21 +23,18 @@ class XBT_PUBLIC Exec : public Activity_T<Exec> {
   double priority_              = 1.0;
   double bound_                 = 0.0;
   double timeout_               = 0.0;
   double priority_              = 1.0;
   double bound_                 = 0.0;
   double timeout_               = 0.0;
-  std::atomic_int_fast32_t refcount_{0};
 
 protected:
   Exec();
 
 protected:
   Exec();
-  virtual ~Exec() = default;
 
 public:
 
 public:
+  virtual ~Exec() = default;
 #ifndef DOXYGEN
   Exec(Exec const&) = delete;
   Exec& operator=(Exec const&) = delete;
 
   friend ExecSeq;
   friend ExecPar;
 #ifndef DOXYGEN
   Exec(Exec const&) = delete;
   Exec& operator=(Exec const&) = delete;
 
   friend ExecSeq;
   friend ExecPar;
-  friend XBT_PUBLIC void intrusive_ptr_release(Exec* e);
-  friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec* e);
 #endif
   static xbt::signal<void(Actor const&, Exec const&)> on_start;
   static xbt::signal<void(Actor const&, Exec const&)> on_completion;
 #endif
   static xbt::signal<void(Actor const&, Exec const&)> on_start;
   static xbt::signal<void(Actor const&, Exec const&)> on_completion;
index c9d55d6..b4ef0c2 100644 (file)
@@ -9,7 +9,6 @@
 #include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
 
 #include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
 
-#include <atomic>
 #include <string>
 
 namespace simgrid {
 #include <string>
 
 namespace simgrid {
@@ -29,15 +28,12 @@ private:
   Disk* disk_       = nullptr;
   sg_size_t size_   = 0;
   OpType type_      = OpType::READ;
   Disk* disk_       = nullptr;
   sg_size_t size_   = 0;
   OpType type_      = OpType::READ;
-  std::atomic_int_fast32_t refcount_{0};
 
   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
   explicit Io(sg_disk_t disk, sg_size_t size, OpType type);
 
 public:
 #ifndef DOXYGEN
 
   explicit Io(sg_storage_t storage, sg_size_t size, OpType type);
   explicit Io(sg_disk_t disk, sg_size_t size, OpType type);
 
 public:
 #ifndef DOXYGEN
-  friend XBT_PUBLIC void intrusive_ptr_release(simgrid::s4u::Io* i);
-  friend XBT_PUBLIC void intrusive_ptr_add_ref(simgrid::s4u::Io* i);
   friend Disk;    // Factory of IOs
   friend Storage; // Factory of IOs
 #endif
   friend Disk;    // Factory of IOs
   friend Storage; // Factory of IOs
 #endif
index c50b10a..98965dc 100644 (file)
@@ -235,16 +235,5 @@ Actor* Comm::get_sender()
   return sender_ ? sender_->ciface() : nullptr;
 }
 
   return sender_ ? sender_->ciface() : nullptr;
 }
 
-void intrusive_ptr_release(simgrid::s4u::Comm* c)
-{
-  if (c->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-    std::atomic_thread_fence(std::memory_order_acquire);
-    delete c;
-  }
-}
-void intrusive_ptr_add_ref(simgrid::s4u::Comm* c)
-{
-  c->refcount_.fetch_add(1, std::memory_order_relaxed);
-}
 } // namespace s4u
 } // namespace simgrid
 } // namespace s4u
 } // namespace simgrid
index 0bee8d4..2511d76 100644 (file)
@@ -68,19 +68,6 @@ Exec* Exec::cancel()
   return this;
 }
 
   return this;
 }
 
-void intrusive_ptr_release(simgrid::s4u::Exec* e)
-{
-  if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-    std::atomic_thread_fence(std::memory_order_acquire);
-    delete e;
-  }
-}
-
-void intrusive_ptr_add_ref(simgrid::s4u::Exec* e)
-{
-  e->refcount_.fetch_add(1, std::memory_order_relaxed);
-}
-
 /** @brief change the execution bound
  * This means changing the maximal amount of flops per second that it may consume, regardless of what the host may
  * deliver. Currently, this cannot be changed once the exec started.
 /** @brief change the execution bound
  * This means changing the maximal amount of flops per second that it may consume, regardless of what the host may
  * deliver. Currently, this cannot be changed once the exec started.
index 8f1f764..30ebf50 100644 (file)
@@ -96,17 +96,5 @@ sg_size_t Io::get_performed_ioops()
       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
 }
 
       [this]() { return boost::static_pointer_cast<kernel::activity::IoImpl>(pimpl_)->get_performed_ioops(); });
 }
 
-void intrusive_ptr_release(simgrid::s4u::Io* i)
-{
-  if (i->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-    std::atomic_thread_fence(std::memory_order_acquire);
-    delete i;
-  }
-}
-
-void intrusive_ptr_add_ref(simgrid::s4u::Io* i)
-{
-  i->refcount_.fetch_add(1, std::memory_order_relaxed);
-}
 } // namespace s4u
 } // namespace simgrid
 } // namespace s4u
 } // namespace simgrid