Uses different pass count for different parallel queue test cases
[libcds.git] / cds / memory / vyukov_queue_pool.h
index 4c5780971ffb1483f619bd4f3fe5f23c8bf7ccb2..432a7f02d9aeaeeabb68547c65788dd9e5943ff2 100644 (file)
@@ -1,11 +1,11 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -25,7 +25,7 @@
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #ifndef CDSLIB_MEMORY_VYUKOV_QUEUE_ALLOCATOR_H
@@ -33,6 +33,7 @@
 
 #include <cds/details/allocator.h>
 #include <cds/intrusive/vyukov_mpmc_cycle_queue.h>
+#include <cds/details/throw_exception.h>
 
 namespace cds { namespace memory {
 
@@ -76,7 +77,7 @@ namespace cds { namespace memory {
         // Pool of Foo object of size 1024.
         struct pool_traits: public cds::memory::vyukov_queue_pool_traits
         {
-            typedef cds::opt::v::static_buffer< Foo, 1024 > buffer;
+            typedef cds::opt::v::uninitialized_static_buffer< Foo, 1024 > buffer;
         };
         typedef cds::memory::vyukov_queue_pool< Foo, pool_traits > pool_type;
         static pool_type thePool;
@@ -135,7 +136,7 @@ namespace cds { namespace memory {
         //@cond
         void preallocate_pool()
         {
-            m_pFirst = std_allocator().allocate( m_Queue.capacity() );
+            m_pFirst = std_allocator().allocate( m_Queue.capacity());
             m_pLast = m_pFirst + m_Queue.capacity();
 
             for ( value_type * p = m_pFirst; p < m_pLast; ++p ) {
@@ -184,7 +185,7 @@ namespace cds { namespace memory {
 
             value_type * p = m_Queue.pop();
             if ( p ) {
-                assert( from_pool(p) );
+                assert( from_pool(p));
                 return new( p ) value_type;
             }
             // The pool is empty - allocate new from the heap
@@ -205,7 +206,7 @@ namespace cds { namespace memory {
             CDS_UNUSED(n);
 
             if ( p ) {
-                if ( from_pool(p) ) {
+                if ( from_pool(p)) {
                     p->~value_type();
                     // The queue can notify about false fullness state
                     // so we push in loop
@@ -309,7 +310,7 @@ namespace cds { namespace memory {
         ~lazy_vyukov_queue_pool()
         {
             std_allocator a;
-            while ( !m_Queue.empty() )
+            while ( !m_Queue.empty())
                 a.deallocate( m_Queue.pop(), 1 );
         }
 
@@ -387,7 +388,7 @@ namespace cds { namespace memory {
         // Pool of Foo object of size 1024.
         struct pool_traits: public cds::memory::vyukov_queue_pool_traits
         {
-            typedef cds::opt::v::static_buffer< Foo, 1024 > buffer;
+            typedef cds::opt::v::uninitialized_static_buffer< Foo, 1024 > buffer;
         };
         typedef cds::memory::bounded_vyukov_queue_pool< Foo, pool_traits > pool_type;
         static pool_type thePool;
@@ -502,7 +503,7 @@ namespace cds { namespace memory {
 
             if ( !p ) {
                 back_off bkoff;
-                while ( m_Queue.size() ) {
+                while ( m_Queue.size()) {
                     p = m_Queue.pop();
                     if ( p )
                         goto ok;
@@ -510,11 +511,11 @@ namespace cds { namespace memory {
                 }
 
                 // The pool is empty
-                throw std::bad_alloc();
+                CDS_THROW_EXCEPTION( std::bad_alloc());
             }
 
         ok:
-            assert( from_pool(p) );
+            assert( from_pool(p));
             return p;
         }
 
@@ -535,7 +536,7 @@ namespace cds { namespace memory {
                 back_off bkoff;
                 // The queue can notify it is full but that is false fullness state
                 // So, we push in loop
-                while ( !m_Queue.push(*p) )
+                while ( !m_Queue.push(*p))
                     bkoff();
             }
         }