From: khizmax Date: Sun, 15 Mar 2015 18:27:16 +0000 (+0300) Subject: Fixed the pool based on Vyukov's queue X-Git-Tag: v2.1.0~305^2~1 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ecc55ea8ad1928e0fa85c973934790a40e1af301;p=libcds.git Fixed the pool based on Vyukov's queue --- diff --git a/cds/memory/vyukov_queue_pool.h b/cds/memory/vyukov_queue_pool.h index c0c5d676..edd75f03 100644 --- a/cds/memory/vyukov_queue_pool.h +++ b/cds/memory/vyukov_queue_pool.h @@ -161,7 +161,7 @@ namespace cds { namespace memory { assert( from_pool(p) ); return p; } - + // The pool is empty - allocate new from the heap return cxx_allocator().New(); } @@ -394,8 +394,13 @@ namespace cds { namespace memory { template class bounded_vyukov_queue_pool { + //@cond + struct internal_traits : public Traits { + typedef cds::atomicity::item_counter item_counter; + }; + //@endcond public: - typedef cds::intrusive::VyukovMPMCCycleQueue< T, Traits > queue_type ; ///< Queue type + typedef cds::intrusive::VyukovMPMCCycleQueue< T, internal_traits > queue_type ; ///< Queue type public: typedef T value_type; ///< Value type @@ -464,12 +469,23 @@ namespace cds { namespace memory { CDS_UNUSED( n ); value_type * p = m_Queue.pop(); - if ( p ) { - assert( from_pool(p) ); - return p; + + if ( !p ) { + back_off bkoff; + while ( m_Queue.size() ) { + p = m_Queue.pop(); + if ( p ) + goto ok; + bkoff(); + } + + // The pool is empty + throw std::bad_alloc(); } - throw std::bad_alloc(); + ok: + assert( from_pool(p) ); + return p; } /// Deallocated the object \p p