Applied patch c1258.diff from Stephan Bruns (ticket:359)
authorgit <git@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 15 Aug 2009 02:49:48 +0000 (02:49 +0000)
committergit <git@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 15 Aug 2009 02:49:48 +0000 (02:49 +0000)
This patch changes pmt_t to use boost intrusive pointers.

Patch was modified to apply to new pmt location since the
original patch was created, and add missing include file.

Signed-off-by: Johnathan Corgan <jcorgan@corganenterprises.com>
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11595 221aa14e-8319-0410-a670-987f0aec2ac5

gruel/src/include/gruel/pmt.h
gruel/src/lib/pmt/pmt.cc
gruel/src/lib/pmt/pmt_int.h

index de0998b5e1bf6e51cc58da7e7ac2182c47ce648f..caa12209d56da8500176d0df915e3bd5298109e5 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef INCLUDED_PMT_H
 #define INCLUDED_PMT_H
 
-#include <boost/shared_ptr.hpp>
+#include <boost/intrusive_ptr.hpp>
 #include <boost/any.hpp>
 #include <complex>
 #include <string>
@@ -50,8 +50,10 @@ class pmt_base;
  * \brief typedef for shared pointer (transparent reference counting).
  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
  */
-typedef boost::shared_ptr<pmt_base> pmt_t;
+typedef boost::intrusive_ptr<pmt_base> pmt_t;
 
+extern void intrusive_ptr_add_ref(pmt_base*);
+extern void intrusive_ptr_release(pmt_base*);
 
 class pmt_exception : public std::logic_error
 {
index fbf557be1e2577a3074928e7ddfba315a6b3e340..fd4035f75f8687e8029a25cdf69ac2546c4c7452 100644 (file)
@@ -56,6 +56,8 @@ pmt_base::operator delete(void *p, size_t size)
 
 #endif
 
+void intrusive_ptr_add_ref(pmt_base* p) { ++(p->count_); }
+void intrusive_ptr_release(pmt_base* p) { if (--(p->count_) == 0 ) delete p; }
 
 pmt_base::~pmt_base()
 {
index 9aac322a7fc7085cce6b56f97f21d653a590152e..ba865b418979f51968e3280649d71433a15438f9 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <gruel/pmt.h>
 #include <boost/utility.hpp>
+#include <boost/detail/atomic_count.hpp>
 
 /*
  * EVERYTHING IN THIS FILE IS PRIVATE TO THE IMPLEMENTATION!
 namespace pmt {
 
 class pmt_base : boost::noncopyable {
+  mutable boost::detail::atomic_count count_;
+
 protected:
-  pmt_base(){};
+  pmt_base() : count_(0) {};
   virtual ~pmt_base();
 
 public:
@@ -66,6 +69,9 @@ public:
   virtual bool is_c32vector() const { return false; }
   virtual bool is_c64vector() const { return false; }
 
+  friend void intrusive_ptr_add_ref(pmt_base* p);
+  friend void intrusive_ptr_release(pmt_base* p);
+
 # if (PMT_LOCAL_ALLOCATOR)
   void *operator new(size_t);
   void operator delete(void *, size_t);