Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57660 - in sandbox/fiber: boost/fiber libs/fiber/examples
From: oliver.kowalke_at_[hidden]
Date: 2009-11-14 14:29:17


Author: olli
Date: 2009-11-14 14:29:16 EST (Sat, 14 Nov 2009)
New Revision: 57660
URL: http://svn.boost.org/trac/boost/changeset/57660

Log:
- unbounded_fifo and bounded_fifo support intrusive-ptr

Text files modified:
   sandbox/fiber/boost/fiber/bounded_fifo.hpp | 15 +++++++++++++--
   sandbox/fiber/boost/fiber/unbounded_fifo.hpp | 12 +++++++++++-
   sandbox/fiber/libs/fiber/examples/ping_pong.cpp | 3 ++-
   3 files changed, 26 insertions(+), 4 deletions(-)

Modified: sandbox/fiber/boost/fiber/bounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/bounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/bounded_fifo.hpp 2009-11-14 14:29:16 EST (Sat, 14 Nov 2009)
@@ -66,6 +66,7 @@
         condition not_full_cond_;
         std::size_t hwm_;
         std::size_t lwm_;
+ volatile uint32_t use_count_;
 
         bool active_() const
         { return 0 == state_; }
@@ -110,7 +111,8 @@
                 not_empty_cond_(),
                 not_full_cond_(),
                 hwm_( hwm),
- lwm_( lwm)
+ lwm_( lwm),
+ use_count_( 0)
         {
                 if ( hwm_ < lwm_)
                         throw std::invalid_argument("invalid watermark");
@@ -126,7 +128,8 @@
                 not_empty_cond_(),
                 not_full_cond_(),
                 hwm_( wm),
- lwm_( wm)
+ lwm_( wm),
+ use_count_( 0)
         {}
 
         void upper_bound_( std::size_t hwm)
@@ -295,6 +298,14 @@
                 }
                 return valid;
         }
+
+ template< typename R >
+ friend void intrusive_ptr_add_ref( bounded_fifo< R > * p)
+ { detail::atomic_fetch_add( & p->use_count_, 1); }
+
+ template< typename R >
+ friend void intrusive_ptr_release( bounded_fifo< R > * p)
+ { if ( detail::atomic_fetch_sub( & p->use_count_, 1) == 1) delete p; }
 };
 
 }}

Modified: sandbox/fiber/boost/fiber/unbounded_fifo.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/unbounded_fifo.hpp (original)
+++ sandbox/fiber/boost/fiber/unbounded_fifo.hpp 2009-11-14 14:29:16 EST (Sat, 14 Nov 2009)
@@ -62,6 +62,7 @@
         typename node::ptr_t tail_;
         mutex tail_mtx_;
         condition not_empty_cond_;
+ uint32_t use_count_;
 
         bool active_() const
         { return 0 == state_; }
@@ -93,7 +94,8 @@
                 head_mtx_(),
                 tail_( head_),
                 tail_mtx_(),
- not_empty_cond_()
+ not_empty_cond_(),
+ use_count_( 0)
         {}
 
         void deactivate()
@@ -176,6 +178,14 @@
                 pop_head_();
                 return va;
         }
+
+ template< typename R >
+ friend void intrusive_ptr_add_ref( unbounded_fifo< R > * p)
+ { detail::atomic_fetch_add( & p->use_count_, 1); }
+
+ template< typename R >
+ friend void intrusive_ptr_release( unbounded_fifo< R > * p)
+ { if ( detail::atomic_fetch_sub( & p->use_count_, 1) == 1) delete p; }
 };
 
 }}

Modified: sandbox/fiber/libs/fiber/examples/ping_pong.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/examples/ping_pong.cpp (original)
+++ sandbox/fiber/libs/fiber/examples/ping_pong.cpp 2009-11-14 14:29:16 EST (Sat, 14 Nov 2009)
@@ -3,6 +3,7 @@
 #include <string>
 
 #include <boost/assert.hpp>
+#include <boost/intrusive_ptr.hpp>
 #include <boost/ref.hpp>
 #include <boost/optional.hpp>
 #include <boost/system/system_error.hpp>
@@ -10,7 +11,7 @@
 #include <boost/fiber.hpp>
 
 typedef boost::fibers::unbounded_fifo< std::string > fifo_t;
-typedef boost::shared_ptr< fifo_t > fifo_ptr_t;
+typedef boost::intrusive_ptr< fifo_t > fifo_ptr_t;
 inline
 void ping(
                 fifo_ptr_t & recv_buf,


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk