commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 01/01: pmt: Adding memory fence to ~pmt_t f


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/01: pmt: Adding memory fence to ~pmt_t for proper multi-core ARM execution.
Date: Thu, 1 Dec 2016 18:37:24 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit 8f590d7bfaa22a42ccb2392f9822206ed003c82a
Author: Darek Kawamoto <address@hidden>
Date:   Thu Dec 1 11:59:03 2016 -0500

    pmt: Adding memory fence to ~pmt_t for proper multi-core ARM execution.
    
    Occasionally, flowgraphs running on my E3xx processor would segfault in the 
pmt_t destructor (an odd place to crash).  When this segfault happens, it's 
common (but not guaranteed) for the top of the coredump backtrace to be at 
0x0000001c or 0x00000018. Always near or at the top was always a pmt 
destructor, such as ~pmt_pair() or ~pmt_tuple().
    
    After reading up in Boost Reference Counter Example Implementation, it 
seems as though we need to add a memory fence to ensure proper memory ordering 
(this issue did not happen on Intel processors due to the stronger memory model 
there).
    
    This commit changes the pmt_t's internal implementation (pmt_int.h and 
pmt.cc) of intrusive_ptr_add_ref and intrusive_ptr_release to be exactly like 
boost's recommended example, and seems to prevent this kind of segfault.
    
    Additionally, since Ubuntu 12.04 comes with boost 1.48, which does not have 
boost/atomic.hpp, the changes are wrapped in #if conditions until support for 
this configuration is discontinued.
---
 gnuradio-runtime/lib/pmt/pmt.cc    | 19 ++++++++++++++++++-
 gnuradio-runtime/lib/pmt/pmt_int.h | 21 ++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index e09452e..204befe 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -63,9 +63,26 @@ pmt_base::operator delete(void *p, size_t size)
 
 #endif
 
+#if ((BOOST_VER_MAJOR >= 1) && (BOOST_VER_MINOR >= 53))
+void intrusive_ptr_add_ref(pmt_base* p)
+{
+  p->refcount_.fetch_add(1, boost::memory_order_relaxed);
+}
+
+void intrusive_ptr_release(pmt_base* p) {
+  if (p->refcount_.fetch_sub(1, boost::memory_order_release) == 1) {
+    boost::atomic_thread_fence(boost::memory_order_acquire);
+    delete p;
+  }
+}
+#else
+// boost::atomic not available before 1.53
+// This section will be removed when support for boost 1.48 ceases
+// NB: This code is prone to segfault on non-Intel architectures.
 void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); }
 void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; }
-
+#endif
+ 
 pmt_base::~pmt_base()
 {
   // nop -- out of line virtual destructor
diff --git a/gnuradio-runtime/lib/pmt/pmt_int.h 
b/gnuradio-runtime/lib/pmt/pmt_int.h
index 49bde52..de91d0e 100644
--- a/gnuradio-runtime/lib/pmt/pmt_int.h
+++ b/gnuradio-runtime/lib/pmt/pmt_int.h
@@ -24,7 +24,13 @@
 
 #include <pmt/pmt.h>
 #include <boost/utility.hpp>
-#include <boost/detail/atomic_count.hpp>
+#if ((BOOST_VER_MAJOR >= 1) && (BOOST_VER_MINOR >= 53)) 
+  #include <boost/atomic.hpp>
+#else
+  // boost::atomic not available before 1.53
+  // This section will be removed when support for boost 1.48 ceases
+  #include <boost/detail/atomic_count.hpp>
+#endif
 
 /*
  * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION!
@@ -36,10 +42,23 @@
 namespace pmt {
 
 class PMT_API pmt_base : boost::noncopyable {
+
+#if ((BOOST_VER_MAJOR >= 1) && (BOOST_VER_MINOR >= 53)) 
+  mutable boost::atomic<int> refcount_;
+#else
+  // boost::atomic not available before 1.53
+  // This section will be removed when support for boost 1.48 ceases
   mutable boost::detail::atomic_count count_;
+#endif
 
 protected:
+#if ((BOOST_VER_MAJOR >= 1) && (BOOST_VER_MINOR >= 53)) 
+  pmt_base() : refcount_(0) {};
+#else
+  // boost::atomic not available before 1.53
+  // This section will be removed when support for boost 1.48 ceases
   pmt_base() : count_(0) {};
+#endif
   virtual ~pmt_base();
 
 public:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]