[Boost-bugs] [Boost C++ Libraries] #5690: intrusive_ptr detach method

Subject: [Boost-bugs] [Boost C++ Libraries] #5690: intrusive_ptr detach method
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-07-12 15:22:40


#5690: intrusive_ptr detach method
------------------------------+---------------------------------------------
 Reporter: nn-mail@… | Owner: pdimov
     Type: Patches | Status: new
Milestone: To Be Determined | Component: smart_ptr
  Version: Boost 1.47.0 | Severity: Optimization
 Keywords: intrusive_ptr |
------------------------------+---------------------------------------------
 It is very handy.
 In some cases like passing between threads or between functions.

 (e.g. Boost.ASIO needs this too)

 Instead of writing this code:
 {{{
 #!cpp

 intrusive_ptr<A> a(get_a());

 intrusive_add_ref(a.get());
 call(a.get());
 }}}

 One could write
 {{{
 #!cpp

 intrusive_ptr<A> a(get_a());

 call(a.detach());
 }}}

 The good thing in the second variation that we don't increase counter, so
 no 'lock' opcode to the processor. Better performance.

 Patch:
 {{{
 #!cpp
         void* detach()
         {
                 T * tmp = px;
                 px = 0;
                 return tmp;
         }
 }}}

 Thanx.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5690>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC