Added update desc pool to intrusive EllenBinTree unit test
authorkhizmax <khizmax@gmail.com>
Tue, 12 Apr 2016 14:08:37 +0000 (17:08 +0300)
committerkhizmax <khizmax@gmail.com>
Tue, 12 Apr 2016 14:08:37 +0000 (17:08 +0300)
test/unit/tree/intrusive_ellenbintree_dhp.cpp
test/unit/tree/intrusive_ellenbintree_hp.cpp

index 58a8213..f5b3b1a 100644 (file)
@@ -31,8 +31,8 @@
 #include "test_intrusive_tree_hp.h"
 
 #include <cds/intrusive/ellen_bintree_dhp.h>
-//#include <cds/memory/vyukov_queue_pool.h>
-//#include <cds/memory/pool_allocator.h>
+#include <cds/memory/vyukov_queue_pool.h>
+#include <cds/memory/pool_allocator.h>
 
 namespace {
     namespace ci = cds::intrusive;
@@ -54,6 +54,56 @@ namespace {
         typedef ci::ellen_bintree::internal_node< key_type, member_item_type >           internal_member_node;
         typedef ci::ellen_bintree::update_desc< member_item_type, internal_member_node > update_member_desc;
 
+        // update_desc pools
+        struct pool_traits: public cds::memory::vyukov_queue_pool_traits
+        {
+            typedef cds::opt::v::static_buffer< update_base_desc, 256 > buffer;
+        };
+        typedef cds::memory::vyukov_queue_pool< update_base_desc, pool_traits > pool_type;
+        typedef cds::memory::lazy_vyukov_queue_pool< update_base_desc, pool_traits > lazy_pool_type;
+
+        static pool_type *         s_Pool;
+        static lazy_pool_type *    s_LazyPool;
+
+        struct pool_accessor
+        {
+            typedef pool_type::value_type value_type;
+
+            pool_type& operator()() const
+            {
+                return *s_Pool;
+            }
+        };
+
+        struct lazy_pool_accessor
+        {
+            typedef lazy_pool_type::value_type value_type;
+
+            lazy_pool_type& operator()() const
+            {
+                return *s_LazyPool;
+            }
+        };
+
+        static void SetUpTestCase()
+        {
+            ASSERT_TRUE( s_Pool == nullptr );
+            ASSERT_TRUE( s_LazyPool == nullptr );
+            s_Pool = new pool_type;
+            s_LazyPool = new lazy_pool_type;
+        }
+
+        static void TearDownTestCase()
+        {
+            ASSERT_TRUE( s_Pool != nullptr );
+            ASSERT_TRUE( s_LazyPool != nullptr );
+            delete s_LazyPool;
+            delete s_Pool;
+
+            s_LazyPool = nullptr;
+            s_Pool = nullptr;
+        }
+
         void SetUp()
         {
             struct list_traits : public ci::ellen_bintree::traits
@@ -79,6 +129,8 @@ namespace {
         };
     };
 
+    /*static*/ IntrusiveEllenBinTree_DHP::pool_type *      IntrusiveEllenBinTree_DHP::s_Pool = nullptr;
+    /*static*/ IntrusiveEllenBinTree_DHP::lazy_pool_type * IntrusiveEllenBinTree_DHP::s_LazyPool = nullptr;
 
     TEST_F( IntrusiveEllenBinTree_DHP, base_cmp )
     {
@@ -158,6 +210,38 @@ namespace {
         test( t );
     }
 
+    TEST_F( IntrusiveEllenBinTree_DHP, base_update_desc_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_base_desc, pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
+    TEST_F( IntrusiveEllenBinTree_DHP, base_update_desc_lazy_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_base_desc, lazy_pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
     // member hook
     TEST_F( IntrusiveEllenBinTree_DHP, member_cmp )
     {
@@ -237,4 +321,36 @@ namespace {
         test( t );
     }
 
+    TEST_F( IntrusiveEllenBinTree_DHP, member_update_desc_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_member_desc, pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
+    TEST_F( IntrusiveEllenBinTree_DHP, member_update_desc_lazy_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_member_desc, lazy_pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
 } // namespace
index 9b676f3..384cbc5 100644 (file)
@@ -31,8 +31,8 @@
 #include "test_intrusive_tree_hp.h"
 
 #include <cds/intrusive/ellen_bintree_hp.h>
-//#include <cds/memory/vyukov_queue_pool.h>
-//#include <cds/memory/pool_allocator.h>
+#include <cds/memory/vyukov_queue_pool.h>
+#include <cds/memory/pool_allocator.h>
 
 namespace {
     namespace ci = cds::intrusive;
@@ -54,6 +54,56 @@ namespace {
         typedef ci::ellen_bintree::internal_node< key_type, member_item_type >           internal_member_node;
         typedef ci::ellen_bintree::update_desc< member_item_type, internal_member_node > update_member_desc;
 
+        // update_desc pools
+        struct pool_traits: public cds::memory::vyukov_queue_pool_traits
+        {
+            typedef cds::opt::v::static_buffer< update_base_desc, 256 > buffer;
+        };
+        typedef cds::memory::vyukov_queue_pool< update_base_desc, pool_traits > pool_type;
+        typedef cds::memory::lazy_vyukov_queue_pool< update_base_desc, pool_traits > lazy_pool_type;
+
+        static pool_type *         s_Pool;
+        static lazy_pool_type *    s_LazyPool;
+
+        struct pool_accessor
+        {
+            typedef pool_type::value_type value_type;
+
+            pool_type& operator()() const
+            {
+                return *s_Pool;
+            }
+        };
+
+        struct lazy_pool_accessor
+        {
+            typedef lazy_pool_type::value_type value_type;
+
+            lazy_pool_type& operator()() const
+            {
+                return *s_LazyPool;
+            }
+        };
+
+        static void SetUpTestCase()
+        {
+            ASSERT_TRUE( s_Pool == nullptr );
+            ASSERT_TRUE( s_LazyPool == nullptr );
+            s_Pool = new pool_type;
+            s_LazyPool = new lazy_pool_type;
+        }
+
+        static void TearDownTestCase()
+        {
+            ASSERT_TRUE( s_Pool != nullptr );
+            ASSERT_TRUE( s_LazyPool != nullptr );
+            delete s_LazyPool;
+            delete s_Pool;
+
+            s_LazyPool = nullptr;
+            s_Pool = nullptr;
+        }
+
         void SetUp()
         {
             struct list_traits : public ci::ellen_bintree::traits
@@ -80,6 +130,9 @@ namespace {
         };
     };
 
+    /*static*/ IntrusiveEllenBinTree_HP::pool_type *         IntrusiveEllenBinTree_HP::s_Pool = nullptr;
+    /*static*/ IntrusiveEllenBinTree_HP::lazy_pool_type *    IntrusiveEllenBinTree_HP::s_LazyPool = nullptr;
+
 
     TEST_F( IntrusiveEllenBinTree_HP, base_cmp )
     {
@@ -159,6 +212,38 @@ namespace {
         test( t );
     }
 
+    TEST_F( IntrusiveEllenBinTree_HP, base_update_desc_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_base_desc, pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
+    TEST_F( IntrusiveEllenBinTree_HP, base_update_desc_lazy_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::base_hook< ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<base_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_base_desc, lazy_pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, base_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
     // member hook
     TEST_F( IntrusiveEllenBinTree_HP, member_cmp )
     {
@@ -238,4 +323,36 @@ namespace {
         test( t );
     }
 
+    TEST_F( IntrusiveEllenBinTree_HP, member_update_desc_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_member_desc, pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
+    TEST_F( IntrusiveEllenBinTree_HP, member_update_desc_lazy_pool )
+    {
+        struct tree_traits: public generic_traits
+        {
+            typedef ci::ellen_bintree::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
+            typedef base_class::less<member_item_type> less;
+            typedef cds::atomicity::item_counter item_counter;
+            typedef cds::memory::pool_allocator<update_member_desc, lazy_pool_accessor> update_desc_allocator;
+        };
+
+        typedef ci::EllenBinTree< gc_type, key_type, member_item_type, tree_traits > tree_type;
+
+        tree_type t;
+        test( t );
+    }
+
 } // namespace