diff options
-rw-r--r-- | gnuradio-runtime/lib/pmt/pmt.cc | 19 | ||||
-rw-r--r-- | 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 e09452e60e..204befebaa 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 49bde52063..de91d0ec5b 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: |