Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please clang and gcc10
[simgrid.git] / include / simgrid / s4u / Activity.hpp
index db486e9..e379e4d 100644 (file)
@@ -7,7 +7,9 @@
 #define SIMGRID_S4U_ACTIVITY_HPP
 
 #include "xbt/asserts.h"
+#include <atomic>
 #include <simgrid/forward.h>
+#include <string>
 #include <xbt/signal.hpp>
 
 namespace simgrid {
@@ -99,8 +101,19 @@ private:
   std::string name_             = "";
   std::string tracing_category_ = "";
   void* user_data_              = nullptr;
+  std::atomic_int_fast32_t refcount_{0};
 
 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");