Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make it possible to return intrusive_ptr in simcalls
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 4 Jun 2017 07:10:57 +0000 (09:10 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 5 Jun 2017 20:21:49 +0000 (22:21 +0200)
include/simgrid/forward.h
src/kernel/activity/ActivityImpl.cpp
src/kernel/activity/ActivityImpl.hpp
src/simix/popping_private.h

index ff78fe3..a387d1c 100644 (file)
@@ -17,9 +17,11 @@ namespace simgrid {
 namespace kernel {
 namespace activity {
 class ActivityImpl;
-     }
-     namespace routing {
-     class NetPoint;
+XBT_PUBLIC(void) intrusive_ptr_add_ref(ActivityImpl* activity);
+XBT_PUBLIC(void) intrusive_ptr_release(ActivityImpl* activity);
+}
+namespace routing {
+class NetPoint;
      }
   }
   namespace simix {
index 77e6570..c732b28 100644 (file)
@@ -1,21 +1,25 @@
-/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/activity/ActivityImpl.hpp"
 
-simgrid::kernel::activity::ActivityImpl::ActivityImpl() = default;
-simgrid::kernel::activity::ActivityImpl::~ActivityImpl() = default;
+namespace simgrid {
+namespace kernel {
+namespace activity {
 
-void simgrid::kernel::activity::ActivityImpl::ref()
+ActivityImpl::ActivityImpl()  = default;
+ActivityImpl::~ActivityImpl() = default;
+
+void ActivityImpl::ref()
 {
   // Atomic operation! Do not split in two instructions!
   xbt_assert(refcount_ != 0);
   refcount_++;
 }
 
-void simgrid::kernel::activity::ActivityImpl::unref()
+void ActivityImpl::unref()
 {
   xbt_assert(refcount_ > 0,
              "This activity has a negative refcount! You can only call test() or wait() once per activity.");
@@ -23,3 +27,17 @@ void simgrid::kernel::activity::ActivityImpl::unref()
   if (refcount_ == 0)
     delete this;
 }
+
+// boost::intrusive_ptr<Activity> support:
+void intrusive_ptr_add_ref(simgrid::kernel::activity::ActivityImpl* activity)
+{
+  activity->ref();
+}
+
+void intrusive_ptr_release(simgrid::kernel::activity::ActivityImpl* activity)
+{
+  activity->unref();
+}
+}
+}
+} // namespace simgrid::kernel::activity::
index e144296..1a28a5f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -31,21 +31,13 @@ namespace activity {
     virtual void resume()=0;
     virtual void post() =0; // What to do when a simcall terminates
 
-    // boost::intrusive_ptr<Activity> support:
-    friend void intrusive_ptr_add_ref(ActivityImpl * activity)
-    {
-      activity->ref();
-    }
-
-    friend void intrusive_ptr_release(ActivityImpl * activity)
-    {
-      activity->unref();
-    }
-
     /** @brief Increases the refcount */
     void ref();
     /** @brief Reduces the refcount */
     void unref();
+    // boost::intrusive_ptr<Activity> support:
+    friend void intrusive_ptr_add_ref(ActivityImpl * activity);
+    friend void intrusive_ptr_release(ActivityImpl * activity);
 
   private:
     std::atomic_int_fast32_t refcount_{1};
index abbc756..389f89b 100644 (file)
@@ -9,6 +9,11 @@
 #include <xbt/base.h>
 #include <simgrid/simix.h>
 
+#include <src/kernel/activity/ActivityImpl.hpp>
+#include <src/kernel/activity/CommImpl.hpp>
+
+#include <boost/intrusive_ptr.hpp>
+
 SG_BEGIN_DECL()
 
 /********************************* Simcalls *********************************/
@@ -118,6 +123,19 @@ T* unmarshal(type<T*>, u_smx_scalar const& simcall)
   return static_cast<T*>(simcall.dp);
 }
 
+template <class T>
+inline void marshal(type<boost::intrusive_ptr<T>>, u_smx_scalar& simcall, boost::intrusive_ptr<T> value)
+{
+  intrusive_ptr_add_ref(&*value);
+  simcall.dp = static_cast<void*>(&*value);
+}
+template <class T> inline boost::intrusive_ptr<T> unmarshal(type<boost::intrusive_ptr<T>>, u_smx_scalar const& simcall)
+{
+  boost::intrusive_ptr<T> res = boost::intrusive_ptr<T>(static_cast<T*>(simcall.dp), false);
+  intrusive_ptr_release(&*res);
+  return res;
+}
+
 template<class R, class... T> inline
 void marshal(type<R(*)(T...)>, u_smx_scalar& simcall, R(*value)(T...))
 {