From 134b8933fd898fbd6462d1c3c0175e1f8157a27f Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 15 Jul 2009 01:33:49 +0000 Subject: [PATCH] =?utf8?q?pmt=20performance=20improvement:=20Switch=20from?= =?utf8?q?=20shared=5Fptr=20to=20intrusive=5Fptr=20for=20pmt=5Ft=20(c1258?= =?utf8?q?=20from=20Stefan=20Br=C3=BCns).?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11442 221aa14e-8319-0410-a670-987f0aec2ac5 --- pmt/src/lib/pmt.cc | 2 ++ pmt/src/lib/pmt.h | 6 ++++-- pmt/src/lib/pmt_int.h | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pmt/src/lib/pmt.cc b/pmt/src/lib/pmt.cc index b403c232..315ff1a4 100644 --- a/pmt/src/lib/pmt.cc +++ b/pmt/src/lib/pmt.cc @@ -54,6 +54,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() { diff --git a/pmt/src/lib/pmt.h b/pmt/src/lib/pmt.h index 24963fee..d495b17a 100644 --- a/pmt/src/lib/pmt.h +++ b/pmt/src/lib/pmt.h @@ -23,7 +23,7 @@ #ifndef INCLUDED_PMT_H #define INCLUDED_PMT_H -#include +#include #include #include #include @@ -48,8 +48,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_t; +typedef boost::intrusive_ptr pmt_t; +extern void intrusive_ptr_add_ref(pmt_base*); +extern void intrusive_ptr_release(pmt_base*); class pmt_exception : public std::logic_error { diff --git a/pmt/src/lib/pmt_int.h b/pmt/src/lib/pmt_int.h index a973d30d..af22d451 100644 --- a/pmt/src/lib/pmt_int.h +++ b/pmt/src/lib/pmt_int.h @@ -34,8 +34,10 @@ #define PMT_LOCAL_ALLOCATOR 0 // define to 0 or 1 class pmt_base : boost::noncopyable { + mutable boost::detail::atomic_count count_; + protected: - pmt_base(){}; + pmt_base() : count_(0) {}; virtual ~pmt_base(); public: @@ -65,6 +67,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); -- 2.47.2