issue #76: added cds::atomicity::cache_friendly_item_counter to avoid false sharing
[libcds.git] / test / stress / set / set_type_ellen_bintree.h
index 0d08e2d6eaeb2fb09497b81ec69e6fac7c2e623e..90c01e5432046c610f5c013439fbc1991df16956 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/
@@ -129,11 +129,6 @@ namespace set {
                 typedef cc::ellen_bintree::internal_node< key_type, leaf_node >     internal_node;
                 typedef cc::ellen_bintree::update_desc< leaf_node, internal_node >  update_desc;
             };
-            struct sht {
-                typedef cc::ellen_bintree::node<rcu_sht, key_val>                   leaf_node;
-                typedef cc::ellen_bintree::internal_node< key_type, leaf_node >     internal_node;
-                typedef cc::ellen_bintree::update_desc< leaf_node, internal_node >  update_desc;
-            };
 #endif
         };
 
@@ -141,6 +136,7 @@ namespace set {
             cc::ellen_bintree::key_extractor< typename ellen_bintree_props::key_extractor >
             ,co::less< typename ellen_bintree_props::less >
             ,co::node_allocator< ellen_bintree_pool::internal_node_allocator< int > >
+            ,co::item_counter<cds::atomicity::cache_friendly_item_counter >
         >::type
         {};
 
@@ -180,12 +176,6 @@ namespace set {
             typedef cds::memory::pool_allocator< typename ellen_bintree_props::shb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
         };
         typedef EllenBinTreeSet< rcu_shb, key_type, key_val, traits_EllenBinTreeSet_shb > EllenBinTreeSet_rcu_shb;
-
-        struct traits_EllenBinTreeSet_sht : public traits_EllenBinTreeSet
-        {
-            typedef cds::memory::pool_allocator< typename ellen_bintree_props::sht::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
-        };
-        typedef EllenBinTreeSet< rcu_sht, key_type, key_val, traits_EllenBinTreeSet_sht > EllenBinTreeSet_rcu_sht;
 #endif
 
         //
@@ -219,6 +209,7 @@ namespace set {
             ,co::less< typename ellen_bintree_props::less >
             ,co::node_allocator< ellen_bintree_pool::internal_node_allocator< int > >
             ,co::stat< cc::ellen_bintree::stat<> >
+            ,co::item_counter<cds::atomicity::cache_friendly_item_counter >
         >::type
         {};
 
@@ -258,12 +249,6 @@ namespace set {
             typedef cds::memory::pool_allocator< typename ellen_bintree_props::shb::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
         };
         typedef EllenBinTreeSet< rcu_shb, key_type, key_val, traits_EllenBinTreeSet_stat_shb > EllenBinTreeSet_rcu_shb_stat;
-
-        struct traits_EllenBinTreeSet_stat_sht : public traits_EllenBinTreeSet_stat
-        {
-            typedef cds::memory::pool_allocator< typename ellen_bintree_props::sht::update_desc, ellen_bintree_pool::update_desc_pool_accessor > update_desc_allocator;
-        };
-        typedef EllenBinTreeSet< rcu_sht, key_type, key_val, traits_EllenBinTreeSet_stat_sht > EllenBinTreeSet_rcu_sht_stat;
 #endif
 
     };
@@ -286,10 +271,10 @@ namespace set {
         {
             EXPECT_EQ( stat.m_nInternalNodeCreated, stat.m_nInternalNodeDeleted );
             EXPECT_EQ( stat.m_nUpdateDescCreated, stat.m_nUpdateDescDeleted );
-            //EXPECT_EQ( ellen_bintree_pool::internal_node_counter::m_nAlloc.get(), ellen_bintree_pool::internal_node_counter::m_nFree.get() );
+            //EXPECT_EQ( ellen_bintree_pool::internal_node_counter::m_nAlloc.get(), ellen_bintree_pool::internal_node_counter::m_nFree.get());
             EXPECT_EQ( ellen_bintree_pool::internal_node_counter::m_nAlloc.get(), stat.m_nInternalNodeCreated );
             // true if RCU is not threaded
-            //EXPECT_EQ( stat.m_nInternalNodeDeleted, ellen_bintree_pool::internal_node_counter::m_nFree.get() );
+            //EXPECT_EQ( stat.m_nInternalNodeDeleted, ellen_bintree_pool::internal_node_counter::m_nFree.get());
         }
     }   // namespace ellen_bintree_check
 
@@ -299,16 +284,6 @@ namespace set {
         //typedef EllenBinTreeSet<GC, Key, T, Traits> set_type;
         GC::force_dispose();
         ellen_bintree_check::check_stat( s.statistics());
-/*
-        bool const threaded_rcu = std::is_same<typename set_type::rcu_tag, cds::urcu::general_threaded_tag >::value
-#ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
-            || std::is_same<typename set_type::rcu_tag, signal_threaded_tag >::value
-#endif
-        ;
-        if ( !threaded_rcu ) {
-            EXPECT_EQ( ellen_bintree_pool::internal_node_counter::m_nAlloc.get(), ellen_bintree_pool::internal_node_counter::m_nFree.get());
-        }
-*/
     }
 
     template <typename GC, typename Key, typename T, typename Traits>
@@ -320,7 +295,7 @@ namespace set {
     template <typename GC, typename Key, typename T, typename Traits>
     static inline void check_before_clear( cds::container::EllenBinTreeSet<GC, Key, T, Traits>& s )
     {
-        EXPECT_TRUE( s.check_consistency() );
+        EXPECT_TRUE( s.check_consistency());
     }
 } // namespace set
 
@@ -334,28 +309,45 @@ namespace set {
 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
 #   define CDSSTRESS_EllenBinTreeSet_SHRCU( fixture, test_case, key_type, value_type ) \
         CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_shb,      key_type, value_type ) \
-        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_sht,      key_type, value_type ) \
         CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_shb_stat, key_type, value_type ) \
-        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_sht_stat, key_type, value_type )
+
 #else
 #   define CDSSTRESS_EllenBinTreeSet_SHRCU( fixture, test_case, key_type, value_type )
 #endif
 
 
-#define CDSSTRESS_EllenBinTreeSet( fixture, test_case, key_type, value_type ) \
+#if defined(CDS_STRESS_TEST_LEVEL) && CDS_STRESS_TEST_LEVEL > 0
+#   define CDSSTRESS_EllenBinTreeSet_HP_1( fixture, test_case, key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_hp,       key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_dhp,      key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_rcu_gpb,  key_type, value_type ) \
+
+#   define CDSSTRESS_EllenBinTreeSet_RCU_1( fixture, test_case, key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpi,        key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpi_stat,   key_type, value_type ) \
+        CDSSTRESS_EllenBinTreeSet_SHRCU( fixture, test_case, key_type, value_type )
+
+#else
+#   define CDSSTRESS_EllenBinTreeSet_HP_1( fixture, test_case, key_type, value_type )
+#   define CDSSTRESS_EllenBinTreeSet_RCU_1( fixture, test_case, key_type, value_type )
+#endif
+
+#define CDSSTRESS_EllenBinTreeSet_HP( fixture, test_case, key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_hp,             key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_dhp,            key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpi,        key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpb,        key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpt,        key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_hp,       key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_dhp,      key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_yield_rcu_gpb,  key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_hp_stat,        key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_dhp_stat,       key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpi_stat,   key_type, value_type ) \
+    CDSSTRESS_EllenBinTreeSet_HP_1( fixture, test_case, key_type, value_type ) \
+
+#define CDSSTRESS_EllenBinTreeSet_RCU( fixture, test_case, key_type, value_type ) \
+    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpb,        key_type, value_type ) \
+    CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpt,        key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpb_stat,   key_type, value_type ) \
     CDSSTRESS_EllenBinTreeSet_case( fixture, test_case, EllenBinTreeSet_rcu_gpt_stat,   key_type, value_type ) \
-    CDSSTRESS_EllenBinTreeSet_SHRCU( fixture, test_case, key_type, value_type )
+    CDSSTRESS_EllenBinTreeSet_RCU_1( fixture, test_case, key_type, value_type ) \
+
+#define CDSSTRESS_EllenBinTreeSet( fixture, test_case, key_type, value_type ) \
+    CDSSTRESS_EllenBinTreeSet_HP( fixture, test_case, key_type, value_type ) \
+    CDSSTRESS_EllenBinTreeSet_RCU( fixture, test_case, key_type, value_type ) \
 
 #endif // #ifndef CDSUNIT_SET_TYPE_ELLEN_BINTREE_H