Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to avoid error with mingw: function definition is marked dllimport.
[simgrid.git] / include / simgrid / s4u / Activity.hpp
index 0b5b174..b846b3c 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 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 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");
@@ -125,11 +138,6 @@ public:
   }
 
   void* get_user_data() { return user_data_; }
-  XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_user_data()") AnyActivity* setUserData(void* data)
-  {
-    return set_user_data(data);
-  }
-  XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_user_data()") void* getUserData() { return user_data_; }
 };
 
 } // namespace s4u