Disable SPSC test cases for some queues
[libcds.git] / test / stress / freelist / put_get_single.cpp
index c7d3335868f8e08b212c74fc9fd0762ecbdf6fcf..d0ebddcdd1c81f625633040e17c546e75fc9420b 100644 (file)
@@ -1,7 +1,7 @@
 /*
     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/
@@ -32,7 +32,9 @@
 
 #include <cds/intrusive/free_list.h>
 #include <cds/intrusive/free_list_cached.h>
-#include <cds/intrusive/free_list_tagged.h>
+#ifdef CDS_DCAS_SUPPORT
+#   include <cds/intrusive/free_list_tagged.h>
+#endif
 
 namespace {
     class put_get_single: public cds_test::stress_fixture
@@ -44,10 +46,10 @@ namespace {
         template <typename FreeList >
         struct value_type: public FreeList::node
         {
-            size_t  counter;
+            atomics::atomic<size_t> counter;
 
             value_type()
-                : counter(0) 
+                : counter(0)
             {}
         };
 
@@ -82,7 +84,7 @@ namespace {
                 for ( size_t pass = 0; pass < s_nPassCount; ++pass ) {
                     item_type* p;
                     while ( (p = static_cast<item_type*>( m_FreeList.get())) == nullptr );
-                    p->counter++;
+                    p->counter.fetch_add( 1, atomics::memory_order_relaxed );
                     m_FreeList.put( p );
                 }
             }
@@ -100,6 +102,9 @@ namespace {
                 s_nThreadCount = 1;
             if ( s_nPassCount == 0 )
                 s_nPassCount = 1000;
+
+            // Override the pass count.
+            s_nPassCount = cfg.get_size_t("PutGetSinglePassCount", s_nPassCount);
         }
         //static void TearDownTestCase();
 
@@ -123,7 +128,7 @@ namespace {
             propout() << std::make_pair( "duration", duration );
 
             // analyze result
-            EXPECT_EQ( item.counter, s_nPassCount * s_nThreadCount );
+            EXPECT_EQ( item.counter.load( atomics::memory_order_relaxed ), s_nPassCount * s_nThreadCount );
 
             list.clear( []( typename FreeList::node* ) {} );
         }
@@ -144,6 +149,7 @@ namespace {
     typedef cds::intrusive::CachedFreeList<cds::intrusive::FreeList> cached_free_list;
     CDSSTRESS_FREELIST_F( CachedFreeList, cached_free_list )
 
+#ifdef CDS_DCAS_SUPPORT
     TEST_F( put_get_single, TaggetFreeList )
     {
         struct tagged_ptr {
@@ -152,12 +158,13 @@ namespace {
         };
 
         atomics::atomic<tagged_ptr> tp;
-        if ( tp.is_lock_free() ) {
+        if ( tp.is_lock_free()) {
             cds::intrusive::TaggedFreeList fl;
             test( fl );
         }
         else
             std::cout << "Double-width CAS is not supported\n";
     }
+#endif
 
 } // namespace