X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=cds%2Fmemory%2Fvyukov_queue_pool.h;h=edd75f03a65934269b0cbb641e6dcce766a7f10d;hb=59965ea1b1413553c875402011dbc4b33db2af6f;hp=c0c5d67631fe994632c53384475767c2322390d8;hpb=e93683633c5d12851927290e8adc071cf202f1bd;p=libcds.git 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